[英]ElementClickInterceptedException: Message: element click intercepted Element is not clickable error clicking a radio button using Selenium and Python
[英]Python Selenium: Click on a radio button
我想知道如何使用Python Selenium单击此页面上的按钮。
这是网页:
https://hk.news.yahoo.com/poll/f83b2360-b41c-11e9-8d6b-b77be6568e98
该按钮的源代码为:
<label class="option Cur(p) Ov(h) D(b) Pos(r) Bxsh($BorderLikeBoxShadow) Bdc($borderGray) Px(15px) Py(23px)" data-reactid="43">
<div class="Pos(r) D(tb)" data-reactid="44">
<div class="D(tbc) Ta(c) Va(m)" data-reactid="45"><input type="radio" value="o0" class="D(n) check" name="option" data-reactid="46"><img class="Trsdu(.3s) Op(0.7) Fil($opacityMsOld) Mend(15px) W(26px) H(26px)" src="https://s.yimg.com/ji/news/ybrain/unselect@1x.png" alt="" data-reactid="47"></div>
<div class="D(tbc) Va(m) Lh(1.5) C($c-fuji-grey-i) LineClamp(1) Fz(16px)" data-reactid="48">支持</div>
</div>
</label>
我尝试了如下脚本,但是没有用。
import os
import glob
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import WebDriverException
options = webdriver.ChromeOptions()
options.add_argument('window-size=1920x1080')
link_url="https://hk.news.yahoo.com/poll/f83b2360-b41c-11e9-8d6b-b77be6568e98"
driver = webdriver.Chrome('chromedriver', chrome_options=options)
driver.get(link_url)
driver.find_elements_by_xpath("//*[@type='radio']")[0].click()
有什么建议么? 谢谢!
使用WebdriverWait和javaScript Executor在xpath下方单击该元素。
element=WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"(//label[contains(@class,'option Cur(p) Ov(h) D(b) Pos(r)')]//div[contains(@class,'D(tbc) Va(m)')])[1]")))
driver.execute_script("arguments[0].click();",element)
要么
element=WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"(//label[contains(@class,'option Cur(p) Ov(h) D(b) Pos(r)')]//img)[1]")))
driver.execute_script("arguments[0].click();",element)
您需要导入以下内容。
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.