51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2937|回复: 5
打印 上一主题 下一主题

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

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2016-11-18 13:17:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 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'

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    奋斗
    2019-12-31 08:59
  • 签到天数: 975 天

    连续签到: 1 天

    [LV.10]测试总司令

    2#
    发表于 2016-11-18 13:28:17 | 只看该作者
    from appium import webdriver
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    3#
     楼主| 发表于 2016-11-18 14:43:25 | 只看该作者
    Miss_love 发表于 2016-11-18 13:28
    from appium import webdriver

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

    使用道具 举报

  • TA的每日心情
    奋斗
    2019-11-4 11:04
  • 签到天数: 274 天

    连续签到: 1 天

    [LV.8]测试军长

    4#
    发表于 2016-11-18 14:49:01 | 只看该作者
    加上from appium import webdriver试试
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    5#
     楼主| 发表于 2016-11-25 13:08:34 | 只看该作者
    SunnyLan 发表于 2016-11-18 14:49
    加上from appium import webdriver试试

    请问appium和selenium的webdriver有啥区别不?能一起用吗?
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    6#
     楼主| 发表于 2016-11-25 13:09:07 | 只看该作者
    Miss_love 发表于 2016-11-18 13:28
    from appium import webdriver

    请问appium和selenium的webdriver有啥区别不?能一起用吗?
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-9-28 11:23 , Processed in 0.075954 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表