我正在嘗試編寫一個允許我在雲服務上自動登錄的程序。 corrensponding在HTML的用戶名和密碼的字段有:使用硒在雲中自動登錄[python]
<div class="formRow">
<input type="text" name="emailOrUsername" ng-model="emailOrUsername" panono-text-box=
"{ "placeholder": "states.account.logIn.emailOrUsername", "required": true }
" panono-focus="" class="ng-pristine ng-valid panonoTextBox ng-touched" placeholder=
"Email or username *" spellcheck="false">
</div>
<div class="formRow">
<input type="password" name="password" ng-model="password" panono-text-box=
"{ "placeholder": "states.account.logIn.password", "required": true }
" class="ng-pristine ng-untouched ng-valid panonoTextBox" placeholder="Password *" spellcheck="false">
</div>
我寫的代碼是:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
usernameStr = "my_username"
passwordStr = "my_password"
browser = webdriver.Chrome()
browser.get("https://mywebsite.com")
wait = WebDriverWait(browser, 10)
if wait:
username = browser.find_element_by_name("emailOrUsername");
password = browser.find_element_by_name("password")
username.send_keys(usernameStr)
username.send_keys(usernameStr)
我收到此錯誤信息。
加註exception_class(消息,屏幕,堆棧跟蹤) selenium.common.exceptions.NoSuchElementException:消息:沒有這樣 元件:無法找到元素: { 「方法」: 「ID」, 「選擇器」: 「emailOrUsername」}
你有沒有試着用'xpath'方法,而不是'name'或'id'? –