繁体   English   中英

由于谷歌广告无法点击元素

[英]can't click on an element due to google ads

我一直在尝试使用 selenium 进行自动化,需要点击链接,但网页上有谷歌广告,不允许我点击按钮。 我该如何克服这个问题?

这是代码

elem = browser.find_element_by_link_text('Illinois')
elem.click()

这是错误

ElementClickInterceptedException: Message: element click intercepted: Element <a href="/state/IL">...</a> is not clickable at point (497, 858). Other element would receive the click: <iframe frameborder="0" src="https://tpc.googlesyndication.com/safeframe/1-0-37/html/container.html?2ad90d8b823cd41d3186f3484dae4192" id="google_ads_iframe_/1254144/netronline_com-medrectangle-2_0" title="3rd party ad content" name="" scrolling="no" marginwidth="0" marginheight="0" width="970" height="90" data-is-safeframe="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" data-google-container-id="12" style="border: 0px; vertical-align: bottom;" data-load-complete="true"></iframe>

我也试过 webdriver 但出现超时错误

WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[@href='https://Link.com' and contains(.,'Illinois')]"))).click()

试试下面的代码:

linkText= WebDriverWait(browser, 20 ).until( 
EC.element_to_be_clickable(
    (By.LINK_TEXT, "Illinois") ) )
browser.execute_script("arguments[0].click();", linkText)

注意:请将以下导入添加到您的解决方案中

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM