Exercise scenario: Verify Baidu login box inside the [next] there is no automatic login is checked by default.
Specific code:
# coding=utf-8 from selenium import webdriver import time # config driver = webdriver.Chrome() url = 'https://baidu.com' Method # 1: Click Login def press_login(): login = driver.find_element_by_xpath("//*[@id='u1']/a[8]") login.click() Method # 2: Click the user login name def press_login_by_account(): LoginByAccount = driver.find_element_by_xpath ( "// * [@ title = 'user login name']") LoginByAccount.click() # Method three: click the check [Remember] Login def press_auto_login(): AutoLogin = driver.find_element_by_xpath("//*[@name='memberPass']") AutoLogin.click() # start testing driver.get(url) print ( 'successfully entered the URL:', url) time.sleep(2) driver.maximize_window() driver.implicitly_wait(6) # Click to Login press_login() print ( 'click Login successful') time.sleep(2) # Click on username to log in press_login_by_account() print ( 'success clicks users who download') time.sleep(2) #press_auto_login() #time.sleep(1) #press_auto_login() #time.sleep(1) try: driver.find_element_by_xpath("//*[@name='memberPass']").is_selected() print ( 'test is passed, the next automatic login [], selected by default') except Exception as e: print ( 'test fails, check the [next] not automatically log default', format (e))
Reference article: https://blog.csdn.net/u011541946/article/details/69951801