如何单击自定义单选按钮

2024-09-28 23:26:26 发布

您现在位置:Python中文网/ 问答频道 /正文

这一次,我在点击一个自定义单选按钮时遇到了一个问题:https://www.nebraska.gov/LISSearch/search.cgi

当我单击单选按钮(在本例中为id=radio1的单选按钮)时,我得到一个异常

selenium.common.exceptions.element ClickInterceptedException:消息:元素click intercepted:元素在点(153449)处不可单击。其他元素将收到单击: (会话信息:chrome=80.0.3987.163)

我尝试使用xpath和id单击它,两者都给出了相同的错误。我知道错误是什么——它是不可点击的。我想知道我怎么才能绕过这个事实上是点击单选按钮。我还包括了一个单选按钮的图像,设置如下。enter image description here


Tags: httpsid元素searchwwwselenium错误common
1条回答
网友
1楼 · 发布于 2024-09-28 23:26:26

要处理截获的元素异常,uoi可以使用以下代码:

    wait = WebDriverWait(driver, 10)
    radioButton=wait.until(EC.element_to_be_clickable((By.ID, "radio1")))
    ActionChains(driver).move_to_element(radioButton).click().perform()

    wait = WebDriverWait(driver, 10)
    radioButton=wait.until(EC.element_to_be_clickable((By.ID, "radio1")))
    driver.execute_script("arguments[0].click();", radioButton)

注意:添加以下库:

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

相关问题 更多 >