我正在嘗試自動化一些在線活動,但我被困在這個彈出視窗中。
.
等待后,我正在使用 XPath: self.driver.find_element_by_xpath('//*[@id="u_0_8_gw"]').click()
但這給了我這個例外:
NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="u_0_8_gw"]"}
(Session info: chrome=96.0.4664.45)
我也嘗試過使用完整路徑以及 id 和 CSS 選擇器,但都沒有奏效。有什么建議?
更新:HTML 代碼(無法添加為文本)

另外,我的按鈕在這個 div 內。

uj5u.com熱心網友回復:
您需要將 webdriver 定向到彈出視窗。如果您可以提供彈出視窗的 HTML 代碼。我可以向您展示如何將 webdriver 定向到特定視窗。此外,完成有趣的彈出視窗后,您需要將 webdriver 定向到主視窗。
彈出視窗看起來像一個 iFrame。如果是 iframe,則需要按如下方式引導 webdriver:如果 iframe 有 ID,請執行以下命令
driver.switchTo().frame("<iframeId>");
//afterwards execute your click event
self.driver.find_element_by_xpath('//*[@id="u_0_8_gw"]').click()
uj5u.com熱心網友回復:
如果 NoSuchElementException 產生并且 xpath 是正確的,則滾動到目標按鈕:
driver.execute_script('arguments[0].scrollIntoView(true);',
driver.find_element_by_xpath(XPATH OF Target button))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/367316.html
