【问题标题】:Unable to resolve 'No module named Appium' error无法解决“没有名为 Appium 的模块”错误
【发布时间】:2019-09-18 16:54:56
【问题描述】:

我正在使用 browserstack 设置我的自动化环境。我尝试根据他们的说明实现以下代码:

from Appium import webdriver
enter code here`from Appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

userName = "cathytest1"
accessKey = "5u8P4kxrPdw3bCDPtyCU"

desired_caps = {
    "build": "Python Android",
    "device": "Samsung Galaxy S8 Plus",
    "app": "bs://fa77cdc35c9dea891b543c3ab6bf2897b300e229"
}

driver = webdriver.Remote("http://" + userName + ":" + accessKey + "@hub- 
cloud.browserstack.com/wd/hub", desired_caps)

search_element = WebDriverWait(driver, 30).until(
    EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Search 
Wikipedia"))
)
search_element.click()

search_input = WebDriverWait(driver, 30).until(
    EC.element_to_be_clickable((MobileBy.ID, 
"org.wikipedia.alpha:id/search_src_text"))
)
search_input.send_keys("BrowserStack")
time.sleep(5)

search_results = 
driver.find_elements_by_class_name("android.widget.TextView")
assert(len(search_results) > 0)

driver.quit()

但我收到以下错误:

Traceback (most recent call last):
  File "/Applications/Eclipse.app/Contents/MacOS/C:\EclipseWorkspaces\csse120/Browserstack/src/Sample/__init__.py", line 1, in <module>
    from Appium import webdriver
ModuleNotFoundError: No module named 'Appium'

我已经通过 Marketplace 在我的 Eclipse IDE 中设置了 Appium,但问题仍然没有解决。

【问题讨论】:

  • 据我所知,市场 appium 将是某种插件,您必须在您的机器上安装 appium,这应该可以解决问题。
  • 如果你在 shell 中执行 python -c 'from Appium import webdriver' 有什么错误吗?
  • @atline 上面的代码会做什么?我以前没有这样做过
  • 就像您在 bash 终端中打开 python 并输入 from Appium import webdriver 一样,这只是为了缩小您的问题。好像您在 IDE 中运行代码?
  • @atline 是的,我在 Eclipse IDE 中运行代码。当我这样做时,我遇到了上面的错误。

标签: python eclipse appium browserstack


【解决方案1】:

你确定你已经安装了 appium 吗?如果不是,请通过 pip: pip install Appium-Python-Client 安装它,然后尝试在您的代码中将 Appium 替换为 appium。在我的系统中,它工作了

【讨论】:

  • 你必须以管理员身份运行pip;如果你没有 pip,我猜,你可以从 python.org 下载并安装它
  • hi @Kolay.Ne 我已经安装了 pip:上次登录:Tue Apr 30 07:41:39 on console cathy0320:~ Cathy$ pip install Appium-Python-Client 已经满足要求:Appium- ./Library/Python/2.7/lib/python/site-packages (0.36) 中的 Python-Client 已满足要求:.​​/Library/Python/2.7/lib/python/site-packages 中的 selenium>=3.14.1(来自Appium-Python-Client) (3.141.0) 要求已经满足:/Library/Python/2.7/site-packages 中的 urllib3 (来自 selenium>=3.14.1->Appium-Python-Client) (1.24) cathy0320:~ Cathy $
  • 在 python 控制台中运行import appium。一切都是小写!输出是什么?
  • 我已经将 'Appium' 替换为 'appium',但似乎没有修复
  • 能否请您检查一下您的 os.path 中的 apium 模块的路径?
【解决方案2】:

升级到 Python 3,然后安装 Appium。我遇到了同样的问题,一旦更新到 Python 3,它就会得到解决。

  1. 卸载 Python 2.7
  2. 安装 Python 3 及更高版本(最新:Python 3.7.4)
  3. 升级点子
  4. 安装 Appium 客户端 (> pip install appium-python-client)
  5. 然后运行脚本

【讨论】:

    猜你喜欢
    • 2019-11-07
    • 2018-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 2018-06-29
    • 1970-01-01
    • 2022-08-23
    相关资源
    最近更新 更多