您好,我嘗試在 python 中的 selenium 驅動程序的幫助下單擊一個單選按鈕,但它不起作用。這是 HTML 代碼:<input aria-flowto="aria8" aria-label="private key" type="radio" ng-model="walletType" value="pasteprivkey" class="ng-pristine ng-valid ng-empty ng-touched" name="200">這是我的代碼行:browser.find_elements_by_xpath("input[type='radio'][value='pasteprivkey']").click()我收到此錯誤:DevTools listening on ws://127.0.0.1:52666/devtools/browser/da96711c-0446-c01-a90d-0f722691ec4cTraceback (most recent call last): File "C:\Users\Andrei\Desktop\py\teste.py", line 6, in <module> browser.find_element_by_xpath("//*[@type='radio'][@value='pasteprivkey']").click() File "C:\Users\Andrei\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "C:\Users\Andrei\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute return self._parent.execute(command, params) File "C:\Users\Andrei\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute self.error_handler.check_response(response) File "C:\Users\Andrei\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace)selenium.common.exceptions.ElementNotVisibleException: Message: element not visible (Session info: chrome=68.0.3440.106) (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 6.1.7601 SP1 x86_64)有人可以幫我嗎?我還嘗試使用檢查元素復制 xpath,但我得到了這個奇怪的東西:/html/body/section[1]/div[1]/main/article[1]/div[2]/wallet-decrypt-drtv/article/section[1]/label[9]/input
2 回答

回首憶惘然
TA貢獻1847條經驗 獲得超11個贊
錯誤消息表明該元素不可見。
您的選擇IS找到輸入元素,但嘗試點擊時,硒報告是不可見的。Selenium 不允許在完全隱藏或位于其他元素后面的元素上發生單擊事件。
如果無法訪問您的網頁,就無法理解為什么該元素不可見。您可以嘗試以下方法之一;
了解將顯示元素的步驟,并在腳本中執行這些步驟
找到一個應該與之交互的不同元素
使用 Javascript 執行點擊(注意,如果您使用 Selenium 進行測試,我不建議這樣做)
最后;
我還嘗試使用檢查元素復制 xpath,但我得到了這個奇怪的東西
這是一個 XPath,也是您的瀏覽器建議的一個。應該記住,XPath 不是一個確定的東西;一個元素可以被很多很多 XPath 找到。這些 XPath 中有些是好的,有些是壞的。選擇最合適的 XPath 需要自動化的經驗和知識,正如您所見,這很難通過工具實現。
添加回答
舉報
0/150
提交
取消