Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error :name 'webdriver' is not defined for appium

I was recording a sample script through appium Inspector and while I was running, I am getting an error like this. My Script is in python language.

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

Below is my script.

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.")

Please help

like image 469
hari madhav Avatar asked Aug 05 '15 15:08

hari madhav


2 Answers

You need to import webdriver:

from selenium import webdriver
like image 108
alecxe Avatar answered Nov 12 '22 15:11

alecxe


The line it is failing on is wd = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)

At the top of your script you do from selenium.webdriver.firefox.webdriver import WebDriver.

Python is case-sensitive for variable names. You either need to do: wd = WebDriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps) OR from selenium.webdriver.firefox.webdriver import WebDriver as webdriver

I would recommend the former unless there's some reason you need it to be called webdriver.

like image 34
Foon Avatar answered Nov 12 '22 13:11

Foon