无法点击单选按钮,即使使用显式等待硒

  • 本文关键字:等待 单选按钮 python selenium
  • 更新时间 :
  • 英文 :


我试图在网页中选择'Female'单选按钮

import time
import selenium.common.exceptions
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Chrome(executable_path="C:Driverschromechromedriver.exe")
driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")
wait = WebDriverWait(driver, 60)
element = wait.until(EC.element_to_be_clickable((By.ID, "RESULT_RadioButton-7_1")))
driver.execute_script("arguments[0].click();",element)
#element.click()
#driver.find_element_by_id("RESULT_RadioButton-7_1").click()
print(driver.find_element_by_id("RESULT_RadioButton-7_0").is_selected())
print(driver.find_element_by_id("RESULT_RadioButton-7_1").is_selected())

错误:

C:UserskkumaraguruPycharmProjectspythonProjectvenvScriptspython.exe C:/Users/kkumaraguru/PycharmProjects/SeleniumProject/RadioButtons.py
Traceback (most recent call last):
File "C:UserskkumaraguruPycharmProjectsSeleniumProjectRadioButtons.py", line 14, in <module>
element = wait.until(EC.element_to_be_clickable((By.ID, "RESULT_RadioButton-7_1")))
File "C:UserskkumaraguruPycharmProjectspythonProjectvenvlibsite-packagesseleniumwebdriversupportwait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

Process finished with exit code 1

似乎在等待ID为RESULT_RadioButton-7_1的元素出现在页面上时超时了。我会亲自打开页面,以确保存在这样的元素。您可以在浏览器的控制台中使用javascript:document.getElementById("RESULT_RadioButton-7_1")来完成此操作。如果这不起作用,那么试着调试代码,并检查HTML Selenium正在查看的内容,以确保是您所期望的。

你可以使用JS intervention,同时确保最大化Windows的大小如下:

driver = webdriver.Chrome(driver_path)
driver.maximize_window()
driver.implicitly_wait(30)
driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")
#time.sleep(5)
element = driver.find_element(By.ID, "RESULT_RadioButton-7_1")
driver.execute_script("arguments[0].click();", element)

相关内容

  • 没有找到相关文章

最新更新