ajia302 发表于 2016-11-18 13:17:44

求助:python写的appium自动化脚本,运行时报错,求大神帮忙。

本帖最后由 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.75)
    y1=int(l*0.5)
    x2=int(l*0.05)
    driver.swipe(x1,y1,x2,y1,t)
   
def swipeRight(t):
    l=getSize()
    x1=int(l*0.05)
    y1=int(l*0.5)
    x2=int(l*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'

Miss_love 发表于 2016-11-18 13:28:17

from appium import webdriver

ajia302 发表于 2016-11-18 14:43:25

Miss_love 发表于 2016-11-18 13:28
from appium import webdriver

多谢啊,但是又遇到了新情况,就是滑动总是不够理想,有没有比较好的用法推荐一下呢,谢谢啦

SunnyLan 发表于 2016-11-18 14:49:01

加上from appium import webdriver试试

ajia302 发表于 2016-11-25 13:08:34

SunnyLan 发表于 2016-11-18 14:49
加上from appium import webdriver试试

请问appium和selenium的webdriver有啥区别不?能一起用吗?

ajia302 发表于 2016-11-25 13:09:07

Miss_love 发表于 2016-11-18 13:28
from appium import webdriver

请问appium和selenium的webdriver有啥区别不?能一起用吗?
页: [1]
查看完整版本: 求助:python写的appium自动化脚本,运行时报错,求大神帮忙。