简体   繁体   中英

Automate simple login with Python Selenium

I am trying to automate simple login with python selenium, but I am confused what element to catch, because "class" is dynamic

HTML/Java code

在此处输入图像描述

Here the code added:

from selenium import webdriver


driver = webdriver.Chrome("C:\\WebDriver\\chromedriver.exe")
driver.get("https://qachassis.tangocode.com/login")

driver.find_element_by_class_name("sc-dxgOiQ bkWMot").send_keys("Login")
driver.find_element_by_class_name("sc-dxgOiQ bkWMot").send_keys("Password")
driver.find_element_by_name("login-submit-button").click()

May be, you can try this,

from selenium import webdriver


driver = webdriver.Chrome("C:\\WebDriver\\chromedriver.exe")
driver.get("https://qachassis.tangocode.com/login")

driver.find_element_by_xpath("//input[@data-testid='login-user-name-input']").send_keys("Login")
driver.find_element_by_xpath("//input[@data-testid='login-password-input']").send_keys("Password")
driver.find_element_by_xpath("//input[@data-testid='login-submit-button']").click()

sorry there is a mistake in the previous code, please refer below code

enter code here

from selenium import webdriver


driver = webdriver.Chrome("C:\\WebDriver\\chromedriver.exe")
driver.get("https://qachassis.tangocode.com/login")

driver.find_element_by_xpath("//input[@data-testid='login-user-name-input']").send_keys("Login")
driver.find_element_by_xpath("//input[@data-testid='login-password-input']").send_keys("Password")
driver.find_element_by_xpath("//button[@data-testid='login-submit-button']").click()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM