从0开始python学习-27.selenium 简单登录页面脚本

url = 'https://test.com.cn/login'
driver.get(url)

# 获取登录页面需要输入账号密码进行模拟登录操作
user = driver.find_element(By.XPATH,'//*[@id="username"]').send_keys('username')
pwd = driver.find_element(By.XPATH,'//*[@id="selfpwd"]').send_keys('123456')
button = driver.find_element(By.XPATH,'//*[@id="fm1"]/div[5]/div/button').click()
sleep(5)

# 校验是否登录成功
driver.implicitly_wait(5)
msg = driver.find_element(By.XPATH, '//*[@id="msg"]/div/h2')

if msg.text == '登录成功' :
    print(msg.text)
    url1 = 'https://test.com.cn/#/device?userName=%E7%94%B3%E4%BA%91%E9%BE%99'
    driver.get(url1)
else:
    print('登录失败')

sleep(10)
driver.quit()

你可能感兴趣的:(python,python,学习,selenium,测试工具,开发语言)