I'm trying to scrape job listings on a career page. I'm trying to click the load more button, but cant seem to figure it out. i was wondering if someone could help me out -- I keep getting an error saying "Element is not clickable at point x. Other element would receive the click".
this is the link: https://www.bain.com/careers/find-a-role/ the code to change would be the try block:
def button_company_name(driver, page, outer_loop_break, all_links):
"""
Handles pagination by clicking the "next page"/"load more" button.
Parameters:
driver (WebDriver): The Selenium WebDriver instance.
page (int): The current page number. (optional)
outer_loop_break (bool): Flag to indicate when to stop scraping.
all_links (list): List of all links on the current page.
Returns:
tuple: Updated page number and outer_loop_break flag.
"""
try:
# Define the XPath
load_more_button_xpath = '//*[@id="role-search-page-react"]/div/div/div[3]/a'
# Wait for the load more button to be clickable
load_more_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, load_more_button_xpath))
)
# Trying to bring button into view before clicking on it
driver.execute_script("arguments[0].scrollIntoView();", load_more_button)
load_more_button.click()
# Wait for the page to load
time.sleep(5)
except Exception as e:
print(f"Error occurred while trying to click the 'next page' button: {e}")
outer_loop_break = True
return page + 1, outer_loop_break
click()function emulates an actual click and so you get this error. The common workaround would be to use JavaScript to click the element--but I would go with Andrej's approach