得到错误:姓名' webdriver'没有为appium定义

时间:2015-08-05 15:41:38

标签: python selenium selenium-webdriver appium

我正在通过appium Inspector录制示例脚本,当我运行时,我收到这样的错误。我的脚本是python语言。

File "second.py", line 14, in <module>
wd = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps) NameError: name 'webdriver' is not defined

以下是我的剧本。

import os
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.common.action_chains import ActionChains
import time

success = True
desired_caps = {}
desired_caps['appium-version'] = '1.0'
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '8.2'
desired_caps['deviceName'] = 'iPhone 6'
desired_caps['app'] = os.path.abspath('/Users/admin/Library/Developer/Xcode/DerivedData/MyApp-podyodvceucybuaaiiuoprthidqh/Build/Products/Debug-iphonesimulator/MyApp.app')

wd = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
wd.implicitly_wait(60)

def is_alert_present(wd):
    try:
        wd.switch_to_alert().text
        return True
    except:
        return False

try:
    wd.find_element_by_name("Accept").click()
    wd.find_element_by_name("Sign In").click()
finally:
    wd.quit()
    if not success:
        raise Exception("Test failed.")

请帮忙

2 个答案:

答案 0 :(得分:3)

您需要导入webdriver

from selenium import webdriver

答案 1 :(得分:0)

它失败的行是wd = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)

在脚本的顶部,您执行from selenium.webdriver.firefox.webdriver import WebDriver

Python对变量名称区分大小写。你要么做: wd = WebDriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps) 要么 from selenium.webdriver.firefox.webdriver import WebDriver as webdriver

我会推荐前者,除非你需要将它称为webdriver。