from selenium import webdriver
chrome_path = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
options = webdriver.ChromeOptions()
options.binary_location = chrome_path
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://www.example.com/login.phtml")
form = driver.find_element_by_css_selector("form[name='f']")
username_input = form.find_element_by_name("username")
password_input = form.find_element_by_name("pw")
username_input.send_keys("LOGIN")
password_input.send_keys("PASSWORD")
form.find_element_by_tag_name("button").click()
if driver.current_url == "https://www.example.com/index.phtml":
print("Successful login!")
else:
print("Login failed")
在我
driver.quit()
在代码末尾删除它并不能解决问题
2条答案
按热度按时间vsmadaxz1#
使用time.sleep()或selenium.webdriver.support.ui中的WebDriverWait等待页面完全加载。
pod7payv2#
工作代码: