我试图单击这样的链接:
<div class="loading" style="display:none;">
<p class="btn blue"><span>さらに表示</span></p>
<a href="javascript:void(0);" onclick="get_more();"></a>
</div>
我使用了这段代码:
element = WebDriverWait(driver, 30).until(lambda x: x.find_element_by_css_selector(".btn.blue")) # @UnusedVariable
element.click()
我收到这样的错误,该怎么解决?
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <p class="btn blue">...</p> is not clickable at point (391, 577). Other element would receive the click: <a href="javascript:void(0);" onclick="get_more();"></a>
(Session info: headless chrome=69.0.3497.100)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 6.1.7601 SP1 x86_64)
最佳答案
您尝试单击的元素已被其他元素覆盖,以便其他元素获得点击而不是实际元素。
实际元素可能没有被点击的可能性如下:
解决方案:在这里,您必须等到加载程序不可见之后,然后才必须单击实际元素
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
element = wait.until(EC.invisibility_of_element_located((By.ID, 'loader_element_id')))
element_button = wait.until(EC.element_to_be_clickable((By.ID, 'your_button_id')))
element_button.click()
解决方案:在这里,您需要滚动到所需的元素,然后必须执行单击
from selenium.webdriver.common.action_chains import ActionChains
element = driver.find_element_by_id("your_element_id")
actions = ActionChains(driver)
actions.move_to_element(element).perform()
或使用可以使用execute_script
像: driver.execute_script("arguments[0].scrollIntoView();", element)
或使用JavaScript执行点击。 driver.execute_script("arguments[0].click();", element)
注意:如果需要,请根据Python语法进行必要的更正。
关于python-3.x - Python中的 "Other element would receive the click"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52400233/