【pytest框架之web自动化测试】---【TouchActions】selenium鼠标滑动操作
操作方式与touchactions类似,需要注意的是
TouchActions无click方法,需要用action.tap()方法点击元素
1 # -*- coding:utf-8 -*-
2 # author:xjw
3 # date=2021/2/25
4 from selenium.webdriver.common.keys import Keys
5
6 import time
7
8 from selenium import webdriver
9 from selenium.webdriver import TouchActions
10 from selenium.webdriver.common.by import By
11
12
13
14 class Testmove:
15 def setup(self):
16 # self.driver= webdriver.Chrome()
17 option=webdriver.ChromeOptions() #订制启动Chrome的选项
18 option.add_experimental_option('w3c',False)
19 self.driver = webdriver.Chrome(options=option)
20 self.driver.get('http://www.baidu.com')
21 self.driver.maximize_window()
22 self.driver.implicitly_wait(5) #隐式等待
23
24 def teardown(self):
25 self.driver.quit()
26 def test_touchactions_case(self):
27 input1=self.driver.find_element(By.ID,'kw')
28 element = self.driver.find_element(By.ID,'su')
29 input1.send_keys('123')
30 action = TouchActions(self.driver)
31 action.tap(element) #点击元素
32 action.perform()
33 action.scroll_from_element(input1,0,10000)#滑动到最底端
34 action.perform()
35 time.sleep(2)
浙公网安备 33010602011771号