刚刚意识到尽管没有抛出错误,但没有提交登录表单:
from selenium import webdriver
driver_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 problem
options = 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”,但应该是“查找代码 - ICD 10 代码、CPT 代码、HCPCS 代码、ICD 9 代码 - 在线编码器 - 医疗账单和编码”,页面源的其余部分确认登录失败
我在调用 .submit() 后尝试了显式等待:
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
wait(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 until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
我在调用 .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 until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
根据这篇文章,我还在调用 send_keys(password) 之前尝试等待,以防密码字段变得陈旧
相关分类