我正在使用Selenium和Python。我努力使用click()
方法来点击动态创建的单选按钮。下面是收音机的标记。Selenium - 无法点击隐藏的元素
<input version="2" value="1" class="linked-ftb-radio meta(controlNumber=2)" id="radio_1" name="IndexString" reference="TEST 01" type="radio">
<label for="radio_1" id="linked-label" class="radio-label"></label>
我的代码是:
driver.find_element_by_xpath('//*[@id="radio_1"]').click()
但是产生以下错误:
Traceback (most recent call last):
File "index.py", line 41, in <module>
driver.find_element_by_xpath('//*[@id="radio_1"]').click()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/selenium/webdriver/remote/webelement.py", line 74, in click
self._execute(Command.CLICK_ELEMENT)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/selenium/webdriver/remote/webelement.py", line 457, in _execute
return self._parent.execute(command, params)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
无线电似乎是由被按下的标签时改变图像进行模拟。换句话说,点击时,班级变为radio-label selected
。
我怎么可以点击与硒的单选按钮,牢记这是当前不可见?
如果在点击之前添加暂停,会发生什么情况? (这不是解决方案,只是进一步的调试步骤) –
我认为点击标签会选择复选框,你应该一次''driver.find_element_by_css_selector('label [for =“radio_1”]')。click()'和让我知道.. –