Selenium Webdriver with Python:元素不可点击 &无法读取 null 的属性'click'



运行此命令时,我收到错误:

driver.find_element_by_link_text("Confirm").click()
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <a href="javascript:void(0);" class="c-button u-fontSize13 c-button--blue transparent-button js-connect-button js-request-connection" data-href="https://angel.co/user_graph_requests" data-invited-id="5911955">...</a> is not clickable at point (67, 581). Other element would receive the click: `<div class="mfp-container mfp-ajax-holder mfp-s-loading">...</div>`

在搜索有关此问题的答案后,我将上面的代码更改为:

element = driver.find_element_by_link_text("Confirm").click()
driver.execute_script("arguments[0].click();", element)

第一次单击它有效,然后打印此错误:

selenium.common.exceptions.WebDriverException: Message: unknown error: Cannot read property 'click' of null

HTML 代码是:

<a href="javascript:void(0);" class="c-button js-close s-vgLeft0_5 c-button--blue" data-modal="true" data-url="https://angel.co/user_graph_requests/102006082/verify">Confirm</a>

所以这对我有用:

driver.find_element_by_link_text("Confirm").send_keys('n')

感谢大家:)

尝试搜索类:
driver.find_element_by_class("c-button js-close s-vgLeft0_5 c-button--blue").click()

如果您查看错误消息,您将看到另一个元素正在拦截单击。如果不看页面,我不确定,但通常它是像加载器屏幕、弹出窗口等的东西,暂时出现然后消失。还有拦截 DIV 的一个类的暗示,mfp-s-loading ,这进一步让我认为它是某种加载弹出窗口。这里的问题是脚本继续并尝试单击链接的速度快于弹出窗口的加载和卸载速度。在这种情况下,我通常会做的是等待弹出窗口不可见,然后单击链接。

弹出窗口的 HTML 在错误消息中,

<div class="mfp-container mfp-ajax-holder mfp-s-loading">...</div>

因此,您可以使用CSS选择器(如div.mfp-s-loading(找到该元素,以等待它不可见,然后尝试单击。

有时使用 Xpath 更容易尝试:driver.find_element_by_xpath(Xpath(.click((

其中 Xpath 应指向您计划单击的对象

相关内容

最新更新