标签:net utf-8 rom log count() ESS account login print
练习场景:验证百度登录框里面的【下次自动登录】有没有被默认勾选。
具体代码:
# coding=utf-8 from selenium import webdriver import time # config driver = webdriver.Chrome() url = ‘https://baidu.com‘ # 方法一:点击登录 def press_login(): login = driver.find_element_by_xpath("//*[@id=‘u1‘]/a[8]") login.click() # 方法二:点击用户名登录 def press_login_by_account(): LoginByAccount = driver.find_element_by_xpath("//*[@title=‘用户名登录‘]") LoginByAccount.click() # 方法三:点击勾选【下次自动登录】 def press_auto_login(): AutoLogin = driver.find_element_by_xpath("//*[@name=‘memberPass‘]") AutoLogin.click() # 开始测试 driver.get(url) print(‘成功进入网址:‘,url) time.sleep(2) driver.maximize_window() driver.implicitly_wait(6) # 点击登录 press_login() print(‘成功点击登录‘) time.sleep(2) # 点击用户名登录 press_login_by_account() print(‘成功点击用户名登录‘) 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(‘测试通过,【下次自动登录】默认为勾选‘) except Exception as e: print(‘测试失败,【下次自动登录】未默认勾选‘,format(e))
参考文章:https://blog.csdn.net/u011541946/article/details/69951801
Python+Selenium练习(二十)-验证控件是否被选中
标签:net utf-8 rom log count() ESS account login print
原文地址:https://www.cnblogs.com/zhaocbbb/p/12641012.html