剛剛意識到盡管沒有拋出錯誤,但沒有提交登錄表單:from selenium import webdriverdriver_path = "path to chromedriver.exe"url_login = "https://www.findacode.com/signin.html"username = 'jd@mailinator.com'password = 'm%$)-Y95*^.1Gin+' #know it's not best practice to share passwords, but this is a trial account and credentials are necessary to appreciate the problemoptions = webdriver.ChromeOptions()options.add_argument('headless')driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)driver.get(url_login)form = driver.find_element_by_name('login')form.find_element_by_name('id').send_keys(username)form.find_element_by_name('password').send_keys(password)form.find_element_by_xpath("//input[@value='Sign In']").submit()此時沒有錯誤,但登錄不成功:driver.title 是“登錄 - FindACode.com”,但應(yīng)該是“查找代碼 - ICD 10 代碼、CPT 代碼、HCPCS 代碼、ICD 9 代碼 - 在線編碼器 - 醫(yī)療賬單和編碼”,頁面源的其余部分確認(rèn)登錄失敗我在調(diào)用 .submit() 后嘗試了顯式等待:from selenium.webdriver.support.ui import WebDriverWait as waitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Bywait(driver, 10).until(EC.visibility_of_element_located((By.ID, "history"))) # history is an element in post login landing page but not in the pre login page但我收到超時錯誤:Traceback (most recent call last):File "<input>", line 29, in <module>File "...\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in untilraise TimeoutException(message, screen, stacktrace)selenium.common.exceptions.TimeoutException: Message: 我在調(diào)用 .submit() 后嘗試了另一個顯式等待title = "Find-A-Code - ICD 10 Codes, CPT Codes, HCPCS Codes, ICD 9 Codes - Onlne Encoder - Medical Billing and Coding" wait(driver, 10).until(EC.title_is(title))我收到另一個超時錯誤:Traceback (most recent call last):File "<input>", line 30, in <module>File "...\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in untilraise TimeoutException(message, screen, stacktrace)selenium.common.exceptions.TimeoutException: Message: 根據(jù)這篇文章,我還在調(diào)用 send_keys(password) 之前嘗試等待,以防密碼字段變得陳舊
添加回答
舉報
0/150
提交
取消