我是Python新手,想用它自动登录。我找到https://automatetheboringstuff.com/chapter11/并尝试:
#! python3
from selenium import webdriver
browser = webdriver.Firefox()
type(browser)
browser.get('https://forum-studienstiftung.de/')
emailEl = browser.find_element_by_id(username)
不幸的是,这导致:
Traceback (most recent call last): File "", line 1, in emailEl = browser.find_element_by_id(username) NameError: name 'username' is not defined
根据Firefox开发工具,正确的ID是“用户名”。在
用引号将用户名括起来。现在,您正在传递一个名为username的变量,selenium正试图与页面上具有相同值的id匹配。由于值为none,Selenium无法找到它,因此出现错误。在
您试图访问的页面需要时间来加载。在访问元素之前,必须等待元素可见。在
试试这个:
相关问题 更多 >
编程相关推荐