无法单击按钮查看更多结果,获取异常元素不可单击

Can't click the button to view more results, getting exception element not clickable

我正在尝试从该站点抓取一些数据 https://easy.co.il/list/Shopping,当您向下滚动企业列表时,当我尝试使用 .click 单击它时,它末尾有一个按钮可以查看更多结果函数它引发了一个元素不是棘手的异常,我也尝试使用 Keys.ENTER 仍然是相同的异常,我尝试使用此代码等待元素可点击。

results = driver.find_elements_by_xpath('//div[@class="biz-item "]')
print(len(results))

button = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.XPATH, '//button[@id="nextPageButton"]')))

len(results) 打印 25,这是在查看更多结果按钮之前可见的所有企业。

我也试过找到按钮,该元素在页面上可见,但无法点击。

有人可以查看一下吗?谢谢!

您需要 scroll click.Use location_once_scrolled_into_view 之前的元素才能滚动该元素。

driver.get("https://easy.co.il/list/Shopping")
button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//button[@id="nextPageButton"]')))
button.location_once_scrolled_into_view
button.click()

如果您仍然遇到错误,则诱导 java 脚本执行器点击。

driver.get("https://easy.co.il/list/Shopping")
button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//button[@id="nextPageButton"]')))
button.location_once_scrolled_into_view
driver.execute_script("arguments[0].click();", button)

使用.visibility_of_element_located方法,然后滚动:

button = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//button[@id="nextPageButton"]')))
button.location_once_scrolled_into_view
button.click()