我正在使用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()'和讓我知道.. –