簡體   English   中英

無法定位元素:python 中的 selenium

[英]unable to locate element : selenium in python

我是使用 python 和 selenium 編碼的新手。 我嘗試通過其 class 名稱在網頁中查找元素。

    <input type="email" class="whsOnd zHQkBf" jsname="YPqjbf" 
           autocomplete="username" spellcheck="false" tabindex="0" 
           aria-label="Adresse e-mail ou numéro de téléphone" name="identifier" 
           value="" autocapitalize="none" id="identifierId" dir="ltr" 
           data-initial-dir="ltr" data-initial-value="">

但是每次我嘗試過時都會出現這個錯誤。

selenium.common.exceptions.NoSuchElementException:消息:沒有這樣的元素:無法找到元素:{“方法”:“css選擇器”,“選擇器”:“.whsOnd zHQkBf”}

我不明白為什么,因為我已驗證並且我認為它不在 iframe 中,所以我不明白為什么我會收到此消息並且我不知道如何管理錯誤。

這是我的代碼和 html 的圖片:

我的代碼

頁面的 HTML

如果沒有看到您的代碼和 html,很難分辨。 您確定它不在 iframe 中嗎?

如果沒有,您也許可以嘗試使用 xpath 來查找元素。 在 chrome 中檢查網頁時,您可以右鍵單擊該元素並說復制 -> 復制 xpath。 我建議您查看 xpath,這樣您就知道自己在搜索什么。

編輯:嘗試只使用一個 class 名稱,因為 find_element_by_class_name() 只接受一個。

這個:driver.find_element_by_class_name("zHQkBf")

而不是這個: driver.find_element_by_class_name("whsOnd zHQkBf")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM