|
本帖最后由 ajia302 于 2016-11-18 13:19 编辑
该脚本是想在某一页面实现侧滑切换,但是运行到swipe报错,百度了半天也没有结果,求大神帮忙,不胜感激!
最好给一个解决方案啦~
脚本:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from appium.webdriver.common.touch_action import TouchAction
from time import sleep
desired_caps={}
desired_caps['platformName']='Android'
desired_caps['platformVersion']='4.4.2'
desired_caps['deviceName']='HUAWEI P7-L00'
desired_caps['appPackage']='com.tuniu.app.ui'
desired_caps['appActivity']='.homepage.LaunchActivity'
driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
driver.implicitly_wait(10)
driver.find_element_by_id('com.tuniu.app.ui:id/iv_style3_card_1').click()
driver.find_element_by_id('com.tuniu.hotel:id/tv_query').click()
driver.find_element_by_id('com.tuniu.hotel:id/iv_product_small_image').click()
driver.find_element_by_id('com.tuniu.hotel:id/tv_hotel_decorate_time').click()
driver.find_element_by_id('com.tuniu.hotel:id/sdv_hotel_image').click()
def getSize():
x = driver.get_window_size()['width']
y = driver.get_window_size()['height']
return (x, y)
def swipeLeft(t):
l=getSize()
x1=int(l[0]*0.75)
y1=int(l[1]*0.5)
x2=int(l[0]*0.05)
driver.swipe(x1,y1,x2,y1,t)
def swipeRight(t):
l=getSize()
x1=int(l[0]*0.05)
y1=int(l[1]*0.5)
x2=int(l[0]*0.75)
driver.swipe(x1,y1,x2,y1,t)
swipeLeft(1000)
sleep(3)
swipeRight(1000)
sleep(3)
driver.quit()
报错信息:
Traceback (most recent call last):
File "D:\appium\workspace\new test\Scroll-test.py", line 61, in <module>
swipeLeft(1000)
File "D:\appium\workspace\new test\Scroll-test.py", line 50, in swipeLeft
driver.swipe(x1,y1,x2,y1,t)
AttributeError: 'WebDriver' object has no attribute 'swipe'
|
|