错误:
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()
有没有解决方法,或者我可以写没有硒的自动登录代码?
答案 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()
希望这对您有帮助!