Appium [已解决] 求教:新手求教:self.driver.swipe () 执行报错 AttributeError: 'WebDriver' object has no attribute 'swipe'

momoko · 2015年12月30日 · 最后由 万万 回复于 2016年09月23日 · 2836 次阅读

# 我的脚本:

#-*- coding: UTF-8 -*-
import os
import time
import unittest
from selenium import webdriver
from lib2to3.pgen2.driver import Driver
from lib2to3.tests.support import driver

PATH=lambda p:os.path.abspath(os.path.join(os.path.dirname(__file__),p))
global driver

class LoginAndroidTests(unittest.TestCase):
    def setUp(self):
        desired_caps={}
        desired_caps['device'] = 'android'
        desired_caps['platformName']='Android'
        desired_caps['browserName']=''
        desired_caps['version']='4.4.2'
        desired_caps['deviceName']='HUAWEI H60-L01'
        desired_caps['appPackage']='com.vehicles.activities'
        desired_caps['appActivity']='.activity.Init.InitActivity'
        self.driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)

    def tearDown(self):
        self.driver.quit()

    def test_login(self):

        print"开始执行脚本"
        time.sleep(20)
        self.driver.swipe(460,193,460,924,1000)
        print "下拉刷新成功" 

if __name__ == '__main__':
    unittest.main()

省略了登录部分的脚本,因为想快速定位 self.driver.swipe() 的问题。
查过 api 文档了,觉得没有写错,也谷歌过报错了,没有找到解决方案,请指点我一下,非常感谢!

共收到 8 条回复 时间 点赞

from appium import webdriver

#1 楼 @lihuazhang 昨晚发完帖子之后在把本地的文件夹看了一遍,selenium 里面确实没有是在 appium 文件夹下面,非常感谢!

现在我也遇到这个问题,请问没有是在 appium 文件夹下面是什么意思

#coding:utf-8
"""
More involved iOS tests, using UICatalog application.
"""
import unittest
import os
import random
import string
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
# from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.touch_actions import TouchActions
# from selenium.webdriver.common.keys import Keys
import urllib2
import json
from time import sleep

# =================
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# =================

def str_generator(size=6, chars=string.ascii_uppercase + string.digits):
    return ''.join(random.choice(chars) for x in range(size))


class ComplexIOSTests(unittest.TestCase):

    def setUp(self):
        # set up appium
        # ** Important Note **
        # Make sure you have build the UICatalog applcation in your local repository
        #app = os.path.join(os.path.dirname(__file__),
        #                   '../../Desktop/UICatalog/build/release-iphonesimulator',
        #                   'UICatalog.app')
        #app = os.path.abspath(app)

        #app = os.path.abspath('/Users/hulianghai/Desktop/Test/build/Debug-iphonesimulator/UICatalog.app')

        app = "cn.com.10jqka.IHexin"
        self.driver = webdriver.Remote(
            command_executor='http://127.0.0.1:4723/wd/hub',
            desired_capabilities={
                'app': app,
                'udid': '57e95712fdd52a1fce030ed46808f1a98e9b2f5e',
                'platformName': 'iOS',
                #'platformName': '',
                'platformVersion': '9.3',
                'deviceName': 'iPhone 6'
            })
        self._values = []

    def tearDown(self):
        self.driver.quit()


    def test_ihexin03(self):
        self.driver.swipe(start_x = 41, start_y = 577, end_x = 52, end_y = 228, duration = 1000 )


suite = unittest.TestLoader().loadTestsFromTestCase(ComplexIOSTests)
unittest.TextTestRunner(verbosity=2).run(suite)

终端报错如下

HeminWon-Extranet:~ Hm$ python /Users/Hm/Desktop/ITest0704.py
test_ihexin03 (__main__.ComplexIOSTests) ... ERROR

======================================================================
ERROR: test_ihexin03 (__main__.ComplexIOSTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/Hm/Desktop/ITest0704.py", line 73, in test_ihexin03
    self.driver.swipe(start_x = 41, start_y = 577, end_x = 52, end_y = 228, duration = 1000 )
AttributeError: 'WebDriver' object has no attribute 'swipe'


9楼 已删除

#4 楼 @heminwon 你检查一下你的 webdriver 引用。selenium 的把 appium 的覆盖了。。。

#6 楼 @chenhengjie123 恩恩,去掉后解决

from selenium import webdriver
from appium import webdriver
这样写,appium 放后面

#8 楼 @chuhong 我与遇到了相同的报错,但是我的脚本原本就写着 from appium import webdriver 哩;后来在 from appium import webdriver 前面加了 from selenium import webdriver,还是报相同的错误。这是怎么回事呢?求指教😀

万万 [该话题已被删除] 中提及了此贴 09月23日 10:29
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册