缺少1个必需的位置参数ERROR

时间:2019-06-16 14:03:45

标签: python python-3.x selenium google-chrome

错误:

    username_box = driver.find_element_by_name("username")
TypeError: find_element_by_name() missing 1 required positional argument: 'name'

代码:

from selenium import webdriver
import webbrowser

usr = "example1"
pss = "example2"

webbrowser.open_new_tab("https://uonet.uni.opole.pl/login")

driver = webdriver.Chrome
username_box = driver.find_element_by_name("username")
username_box.send_keys(usr)
password_box = driver.find_element_by_name('password')
password_box.send_keys(pss)

accept_button = driver.find_element_by_id('main')

login_button = driver.find_element_by_id('sub1')
login_button.submit()

有没有解决方法,或者我可以写没有硒的自动登录代码?

1 个答案:

答案 0 :(得分:0)

您需要使用chromedriver的路径启动Chrome的实例,并使用get(url) webdriver方法

类似这样的东西:

from selenium import webdriver
import webbrowser

usr = "example1"
pss = "example2"

# webbrowser.open_new_tab("https://uonet.uni.opole.pl/login")

# you can spesify in the initiation of Chrome the path to a spcific chromedriver
# like this: driver = webdriver.Chrome("path/to/chromedriver.exe")
driver = webdriver.Chrome()
driver.get("https://uonet.uni.opole.pl/login")
username_box = driver.find_element_by_name("username")
username_box.send_keys(usr)
password_box = driver.find_element_by_name('password')
password_box.send_keys(pss)

accept_button = driver.find_element_by_id('main')

login_button = driver.find_element_by_id('sub1')
login_button.submit()

希望这对您有帮助!