By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,929 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,929 IT Pros & Developers. It's quick & easy.

Selenium Python Script Issue

P: 1
Hey I am trying to get the hang of both Python and Selenium RC at the same time and having a bit of difficulty and was wondering if anyone here could assist me validating my Python Script. I've gotten rid of most of the initial errors besides one.

Here is my Python Script

Expand|Select|Wrap|Line Numbers
  1. from selenium import selenium
  2. import unittest
  3.  
  4. class SignUpTask(unittest.TestCase):
  5.     """ The following needs to have the issues corrected to make 
  6.         it run. When the run is completed the answer for question 
  7.         2 will be shown"""
  8.  
  9.     def setUp(self):
  10.         self.selenium = selenium("localhost", 4444, "*firefox",
  11.                 "http://www.google.com/")
  12.         self.selenium.start()
  13.  
  14.  
  15.     def test_that_will_print_out_a_url_as_answer_for_task(sel):
  16.         self.selenium.open("/")
  17.         self.selenium.click("link=Web QA")
  18.         self.selenium.wait_for_page_to_load("30000")
  19.         self.selenium.click("link=Get Involved")
  20.         self.selenium.wait_for_page_to_load("30000")
  21.         url = self.selenium.get_attribute("//ol/li[5]/a@href")
  22.         print """The Url below needs to be entered as the answer 
  23.                  for Question 2) in the signup task"""
  24.         print "URL is: %s" % url
  25.  
  26.     def tearDown(self):
  27.         self.selenium.stop()
  28.  
  29. if __name__ == "__main__":
  30.     unittest.main()
I run the Python script and then get the following error:
================================================== ====================
ERROR: test_that_will_print_out_a_url_as_answer_for_task (__main__.SignUpTask)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/eanderson/Desktop/TestFiles/Selenium1.py", line 16, in test_that_will_print_out_a_url_as_answer_for_task
self.selenium.open("/")
NameError: global name 'self' is not defined

----------------------------------------------------------------------
Ran 1 test in 24.577s

Could anyone help me with this "NameError: global name 'self' is not defined" error so my script can parse?

Thank You!!

.erik
Jan 11 '11 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
def test_that_will_print_out_a_url_as_answer_for_task( sel) should be def test_that_will_print_out_a_url_as_answer_for_task( self)
Jan 11 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.