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
You need to import webdriver
:
from selenium import webdriver
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With