• 百度登录、退出示例


     1 # -*- coding:utf-8 -*-
     2 """
     3 百度登录,退出
     4 """
     5 from selenium import webdriver
     6 import unittest
     7 from selenium.webdriver import ActionChains
     8 from selenium.webdriver.support.ui import WebDriverWait
     9 
    10 class Baidu_Demo(unittest.TestCase):
    11     
    12     def setUp(self):
    13         self.driver = webdriver.Firefox()
    14         self.driver.get('http://www.baidu.com')
    15     
    16     def test_login(self):
    17         driver = self.driver
    18         driver.find_element_by_xpath("//*[@id='lb']").click()
    19         driver.find_element_by_name('userName').send_keys('你的帐号')
    20         driver.find_element_by_name('password').send_keys('你的密码')
    21         driver.find_element_by_name('memberPass').click()                   #去掉记住密码
    22         driver.find_element_by_id('TANGRAM__PSP_10__submit').click()
    23         
    24         try:
    25             WebDriverWait(driver, 5).until(lambda x: x.find_element_by_id('s_username_top'))        
    26             myele = driver.find_element_by_id('s_username_top')   
    27             myele_text = myele.text
    28             
    29             action_myele = ActionChains(driver)
    30             action_myele.move_to_element(myele).perform()               #移动鼠标到元素我的帐号上
    31             
    32             WebDriverWait(driver, 5).until(lambda x: x.find_element_by_link_text('退出'))
    33             driver.find_element_by_link_text('退出').click()            #退出登录     
    34         except Exception as e:
    35             print e
    36         
    37         self.assertEqual("你的帐号", myele_text, '登录失败')
    38     
    39     def tearDown(self):
    40         self.driver.quit()
    41         
    42 if __name__ == '__main__':
    43     unittest.main()
     1 # -*- coding:utf-8 -*-
     2 """
     3 百度登录,退出
     4 """
     5 from selenium import webdriver
     6 import unittest
     7 from selenium.webdriver import ActionChains
     8 from selenium.webdriver.support.ui import WebDriverWait
     9 driver = webdriver.Firefox()
    10 class Baidu_Demo(unittest.TestCase):
    11     
    12     def test_login(self):      
    13         driver.get('http://www.baidu.com')  
    14         driver.find_element_by_xpath("//*[@id='lb']").click()
    15         driver.find_element_by_name('userName').send_keys('expect88')
    16         driver.find_element_by_name('password').send_keys('luoqing1227')
    17         driver.find_element_by_name('memberPass').click()                   #去掉记住密码
    18         driver.find_element_by_id('TANGRAM__PSP_10__submit').click()
    19         
    20         self.assertTrue('expect88' in driver.page_source) 
    21    
    22     def test_qiut(self):
    23         WebDriverWait(driver, 5).until(lambda x: x.find_element_by_id('s_username_top'))        
    24         myele = driver.find_element_by_id('s_username_top')
    25             
    26         action_myele = ActionChains(driver)
    27         action_myele.move_to_element(myele).perform()               #移动鼠标到元素我的帐号上
    28             
    29         WebDriverWait(driver, 5).until(lambda x: x.find_element_by_link_text('退出'))
    30         driver.find_element_by_link_text('退出').click()
    31         
    32 if __name__ == '__main__':
    33     unittest.main()
  • 相关阅读:
    【bzoj4917】Hash Killer IV 乱搞
    【bzoj2770】YY的Treap 权值线段树
    【bzoj4898】[Apio2017]商旅 Floyd+分数规划+Spfa
    【GXZ的原创】平衡树性能测试
    【bzoj2969】矩形粉刷 期望
    【bzoj3325】[Scoi2013]密码 逆模拟Manacher
    【bzoj4974】字符串大师 逆模拟KMP
    【bzoj4987】Tree 树形背包dp
    【bzoj3672】[Noi2014]购票 斜率优化dp+CDQ分治+树的点分治
    【bzoj4325】NOIP2015 斗地主(&“加强”版) 搜索
  • 原文地址:https://www.cnblogs.com/Roger1227/p/3189001.html
Copyright © 2020-2023  润新知