Reputation: 13
What have I done wrong? I keep getting this error:
============== RESTART: C:\Users\Redacted\Desktop\Autonav_1.py ==============
E ====================================================================== ERROR: test_autonav_1 (main.Autonav_1) ---------------------------------------------------------------------- Traceback (most recent call last): File "C:\Users\Redacted\Desktop\Autonav_1.py", line 8, in setUp self.selenium = selenium("localhost", 4444, "*firefox", "Redacted") NameError: name 'selenium' is not definedRan 1 test in 0.003s
FAILED (errors=1)
Code:
# -*- coding: utf-8 -*-
from selenium import webdriver
import unittest, time, re
class Autonav_1(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*firefox" "redacted")
self.selenium.start()
def test_autonav_1(self):
sel = self.selenium
sel.open("/hub/login.php")
sel.type("id=Email", "redacted")
sel.type("id=Password", "redacted")
sel.click("id=Login")
sel.wait_for_page_to_load("30000")
sel.click("link=Internet Retailing")
sel.wait_for_page_to_load("30000")
sel.click("id=redacted")
sel.click("id=redacted")
sel.wait_for_page_to_load("30000")
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
Upvotes: 1
Views: 619
Reputation: 59573
You are importing webdriver
from the selenium
library so the name selenium
is not bound to anything.
import selenium.webdriver
driver = selenium.webdriver.Chrome('localhost', 4444, '*firefox', '...')
or
from selenium import webdriver
driver = webdriver.Chrome('localhost', 4444, '*firefox', '...')
An import
directive introduces a name binding for whatever is to the right of the import
keyword. In the first example, two names are bound -- selenium
and selenium.webdriver
. In the second example only a single name is bound. See the python docs on import for more details.
Upvotes: 0
Reputation: 50899
selenium
is the library. You need to use webdriver
def setUp(self):
self.driver = webdriver.Firefox("localhost", 4444, "*firefox" "redacted")
def test_autonav_1(self):
driver = self.driver
Upvotes: 1