我有一个代码,我的问题-启动代码时出错。怎么了?
从硒导入网络驱动程序
driver = webdriver.Chrome('D:\ webdriver firefox \ chromedriver.exe')
driver.get('documentation on get_object
[Django-doc]')
状态= driver.find_element_by_id('RESULT_RadioButton-8_0')。is_selected() 打印(状态)
driver.find_element_by_id('RESULT_RadioButton-8_0')。click()
状态= driver.find_element_by_id('RESULT_RadioButton-8_0')。is_selected() 打印(状态)
答案 0 :(得分:2)
这是解决方案:
from selenium import webdriver
driver = webdriver.Chrome('C:/Users/XYZ/bin/chromedriver.exe')
driver.maximize_window()
driver.get('https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407')
status = driver.find_element_by_css_selector("[name='RESULT_RadioButton-7']").is_selected()
print(status)
driver.find_element_by_css_selector("[for='RESULT_RadioButton-7_0']").click()
status = driver.find_element_by_css_selector("[name='RESULT_RadioButton-7']").is_selected()
print(status)
输出:
False
True
答案 1 :(得分:0)
问题在这里:
Element <input type="radio" name="RESULT_RadioButton-8" class="multiple_choice" id="RESULT_RadioButton-8_0" value="Radio-0"> is not clickable at point (281, 538). Other element would receive the click: <label for="RESULT_RadioButton-8_0">
因此,您需要单击label
,而不是radio input
。可以使用以下XPath expression找到标签:
//label[@for='RESULT_RadioButton-8_0']
因此您需要更改此行:
driver.find_element_by_id('RESULT_RadioButton-8_0').click()
对此:
driver.find_element_by_xpath('//label[@for=\'RESULT_RadioButton-8_0\']').click()