Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 登录表单提交失败,但未引发错误_Python_Html_Selenium - Fatal编程技术网

Python 登录表单提交失败,但未引发错误

Python 登录表单提交失败,但未引发错误,python,html,selenium,Python,Html,Selenium,刚刚意识到登录表单没有提交,尽管没有抛出错误: 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 pas

刚刚意识到登录表单没有提交,尽管没有抛出错误:

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()后,我尝试了显式等待:

但我收到一个超时错误:

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: 
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: 
我收到另一个超时错误:

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: 
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: 
但我似乎无法正确理解语法,文档也没有什么帮助:

Traceback (most recent call last):
File "<input>", line 26, in <module>
TypeError: until() missing 1 required positional argument: 'method'
回溯(最近一次呼叫最后一次):
文件“”,第26行,在
TypeError:until()缺少1个必需的位置参数:“方法”

非常感谢任何指针。

使用下面的css定位器:

driver.find_element_by_css_selector('form[name=login] input[name=id]').send_keys(username)
driver.find_element_by_css_selector('form[name=login] input[name=password]').send_keys(password)
driver.find_element_by_css_selector('form[name=login] input[type="submit"]').click()

提供html或URL。它在帖子中:
https://www.findacode.com/signin.html
在我编辑后生效(在“css”之前添加“by”)。我也更新了你的答案。请解释为什么这种方法比我所做的更有效?这个解释可能对我的最终目标有用。你的问题是提交xpath定位器。当您使用类似xpath的元素搜索子元素时,必须添加按xpath查找元素。在你的选择器前面。在您的情况下,“//input”。
driver.find_element_by_css_selector('form[name=login] input[name=id]').send_keys(username)
driver.find_element_by_css_selector('form[name=login] input[name=password]').send_keys(password)
driver.find_element_by_css_selector('form[name=login] input[type="submit"]').click()