博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
淘宝登录脚本-selenium
阅读量:4487 次
发布时间:2019-06-08

本文共 2639 字,大约阅读时间需要 8 分钟。

import pytest import time import json from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.keys import Keys method=1 class TestUntitled():   def setup_method(self, method):     self.driver = webdriver.Firefox()     self.vars = {}   def teardown_method(self, method):     self.driver.quit();   def test_untitled(self):     # Test name: Untitled     # Step # | name | target | value | comment     # 1 | open | / |  |     self.driver.get("https://www.taobao.com/")     # 2 | setWindowSize | 1801x695 |  |     self.driver.set_window_size(1801, 695)     # 3 | mouseOver | css=#J_SiteNavSeller a > span |  |     element = self.driver.find_element(By.CSS_SELECTOR, "#J_SiteNavSeller a > span")     actions = ActionChains(driver)     actions.move_to_element(element).perform()     # 4 | click | linkText=亲,请登录 |  |     self.driver.find_element(By.LINK_TEXT, "亲,请登录").click()     # 5 | click | css=.ph-label |  |     self.driver.find_element(By.CSS_SELECTOR, ".ph-label").click()     # 6 | type | id=TPL_username_1 | 15850790853 |     self.driver.find_element(By.ID, "TPL_username_1").send_keys("19999999999")     # 7 | click | id=TPL_password_1 |  |     self.driver.find_element(By.ID, "TPL_password_1").click()     # 8 | mouseOver | id=J_SubmitStatic |  |     element = self.driver.find_element(By.ID, "J_SubmitStatic")     actions = ActionChains(driver)     actions.move_to_element(element).perform()     # 9 | type | id=TPL_password_1 | woben123 |     self.driver.find_element(By.ID, "TPL_password_1").send_keys("123456")     # 10 | click | id=J_SubmitStatic |  |     self.driver.find_element(By.ID, "J_SubmitStatic").click()     # 11 | mouseOver | css=.item-1 |  |     element = self.driver.find_element(By.CSS_SELECTOR, ".item-1")     actions = ActionChains(driver)     actions.move_to_element(element).perform()     # 12 | click | id=q |  |     self.driver.find_element(By.ID, "q").click()     # 13 | type | id=q | 1 |     self.driver.find_element(By.ID, "q").send_keys("1")     # 14 | click | css=.btn-search |  |     self.driver.find_element(By.CSS_SELECTOR, ".btn-search").click() if __name__=='__main__':   TestUntitled().setup_method(method)   time.sleep(1)   TestUntitled().test_untitled()   TestUntitled().teardown_method(method)

 

####调用类里面的方法如果方法带self,最后调用时要类后面加()

TestUntitled().test_untitled() 带参数的参数也必须加上
TestUntitled().setup_method(method)

转载于:https://www.cnblogs.com/zhujunsheng/p/11041200.html

你可能感兴趣的文章
java 布局教程_java布局学习(新)
查看>>
你真的会写Java吗?
查看>>
alibaba.fastjson.JSONObject 解析
查看>>
终于有人把Elasticsearch原理讲透了
查看>>
Java使用POI 读取和写入Excel指南
查看>>
shell脚本中各类括号的作用(小结)
查看>>
借用Snippet插件美化博客中的代码
查看>>
深入研究java.lang.Runtime类
查看>>
10677 我们仍未知道那天所看见的花的名字
查看>>
ScanTailor-ScanTailor 自动矫正图像歪斜
查看>>
UVA GCD - Extreme (II)
查看>>
完成个人中心—导航标签
查看>>
前端性能优化
查看>>
static
查看>>
属性动画
查看>>
Hadoop集群时钟同步
查看>>
C++二维数组讲解、二维数组的声明和初始化
查看>>
纹理映射和混合
查看>>
PHP获取域名、IP地址的方法
查看>>
php验证复选框的小例子
查看>>