Appium 【已解决】运行 android_contacts.py 出错,ImportError: No module named switch_to

shuiguolan · 2014年05月21日 · 最后由 唐僧之妈 回复于 2014年05月30日 · 1918 次阅读

import os
import unittest
from appium import webdriver
from time import sleep

Returns abs path relative to this file and not cwd

PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(file), p)
)

class ContactsAndroidTests(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = PATH(
'..../app/ContactManager.apk'
)
desired_caps['appPackage'] = 'com.example.android.contactmanager'
desired_caps['appActivity'] = '.ContactManager'

self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

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

def test_add_contacts(self):
el = self.driver.find_element_by_name("Add Contact")
el.click()

textfields = self.driver.find_elements_by_class_name("android.widget.EditText")
textfields[0].send_keys("Appium User")
textfields[2].send_keys("someone@appium.io")

self.assertEqual('Appium User', textfields[0].text)
self.assertEqual('someone@appium.io', textfields[2].text)

self.driver.find_element_by_name("Save").click()

# for some reason "save" breaks things
alert = self.driver.switch_to_alert()

# no way to handle alerts in Android
self.driver.find_element_by_android_uiautomator('new UiSelector().clickable(true)').click()

self.driver.keyevent(3)

if name == 'main':
suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)

已经安装了 Appium-Python-Client,目前用的 python 是 2.7
Traceback (most recent call last):
File "C:\babyD\myWork\myCode\Appium_Framework_Demo_v1\examples\android_contacts.py", line 8, in
from appium import webdriver
File "build\bdist.win32\egg\appium\webdriver_init_.py", line 19, in

File "build\bdist.win32\egg\appium\webdriver\webdriver.py", line 19, in
File "build\bdist.win32\egg\appium\webdriver\switch_to.py", line 15, in
ImportError: No module named switch_to

共收到 4 条回复 时间 点赞

哪位大侠帮忙看看是什么问题

from appium import webdriver
说明你的 Appium-Python-Client 没有配好,请安装 Readme 文档配置就可以了。

问题找到了,是 eclipse 引了两个不同版本号的 selenium,谢谢大家帮忙

先卸载之前安装的 Selenium,再安装 Appium-Python-Client,安装 Appium-Python-Client 时会自动安装 Selenium

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册