一尘不染

在python中使用selenium填充用户名和密码

selenium

如何通过以下链接自动填写用户名和密码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

chromedriver = 'C:\\chromedriver.exe'
browser = webdriver.Chrome(chromedriver)
browser.get('http://www.example.com')

之后,我真的不知道:

username = Select(browser.find_element_by_name('Username'))
password = Select(browser.find_element_by_name('Password'))
username.select_by_visible_text("text")
password.select_by_visible_text("text")

阅读 567

收藏
2020-06-26

共1个答案

一尘不染

driver = webdriver.Firefox(...)  # Or Chrome(), or Ie(), or Opera()

username = driver.find_element_by_id("username")
password = driver.find_element_by_id("password")

username.send_keys("YourUsername")
password.send_keys("Pa55worD")

driver.find_element_by_name("submit").click()

代码注释:

2020-06-26