我正在尝试使用硒来单击页面上的链接,并在单击按钮后读取某个元素,但是仍然遇到此错误消息:
ElementClickInterceptedException: Message: element click intercepted: Element <li class="clink-hold">...</li> is not clickable at point (367, 727). Other element would receive the click: <iframe id="google_ads_iframe_/21732118914/box_live-medrectangle-2_0" title="3rd party ad content" name="google_ads_iframe_/21732118914/box_live-medrectangle-2_0" width="970" height="90" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" sandbox="allow-forms allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" style="border: 0px; vertical-align: bottom;" data-google-container-id="13" data-load-complete="true"></iframe>
(Session info: chrome=78.0.3904.108)
这是我编写的代码
from selenium import webdriver
from time import sleep
page_link = 'https://box.live/fight-results/'
chromedriver = 'C:\\Users\\User\\Downloads\\chromedriver'
def click_info():
cdriver = webdriver.Chrome(chromedriver)
cdriver.get(page_link)
cdriver.find_element_by_class_name('clink-hold').click()
sleep(10)
text=cdriver.find_element_by_class_name('name').text
print(text)
click_info()
答案 0 :(得分:1)
这是因为有些Google广告与您的按钮重叠:
您需要先关闭广告。这是十字[x]元素:
<span class="ezmob-footer-close" onclick="document.getElementById('ezmobfooter').style.display='none';">x</span>
然后继续您的代码。
答案 1 :(得分:0)
只需添加到已添加的答案中即可。我设法解决了这个问题。我意识到,正如Alexey所提到的,有一个元素(广告)涵盖了我要点击的内容。 这就是我为解决这个问题所做的
def click_info():
cdriver = webdriver.Chrome(chromedriver)
cdriver.get(page_link)
element = cdriver.find_element_by_class_name('clink-hold')
cdriver = cdriver.execute_script('arguments[0].click();',element)
text=cdriver.find_element_by_class_name('contestant-name line-ignore').text
print(text)
答案 2 :(得分:-1)
您需要切换到iframe:
iframe = driver.find_element_by_xpath("//iframe[@class='ifram_class_name']")
然后:
driver.switch_to.frame(iframe)
cdriver.find_element_by_class_name('clink-hold').click()
sleep(10)
text=cdriver.find_element_by_class_name('name').text
print(text)
最后:
driver.switch_to.default_content()