Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hey There. I am trying to get the hang of both Python and Selenium RC and am having some difficulty getting the following sample Selenium Python Script to parse. I have resolved all of the following code's errors besides one:

from selenium import selenium
import unittest

class SignUpTask(unittest.TestCase):
    """ The following needs to have the issues corrected to make 
        it run. When the run is completed the answer for question 
        2 will be shown"""

def setUp(self):
    self.selenium = selenium("localhost", 4444, "*firefox",
            "http://www.google.com/")
    self.selenium.start()


def test_that_will_print_out_a_url_as_answer_for_task(sel):
    self.selenium.open("/")
    self.selenium.click("link=Web QA")
    self.selenium.wait_for_page_to_load("30000")
    self.selenium.click("link=Get Involved")
    self.selenium.wait_for_page_to_load("30000")
    url = self.selenium.get_attribute("//ol/li[5]/a@href")
    print """The Url below needs to be entered as the answer 
             for Question 2) in the signup task"""
    print "URL is: %s" % url

def tearDown(self):
    self.selenium.stop()

if __name__ == "__main__":
    unittest.main()

After running the above script via Selenium RC, I 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

failed (errors=1)

Does anyone out there understand why I am getting the "NameError: global name 'self' is not defined" error on line 16 and could help me alleviate this error so my script can parse without error.

Thanks!

.erik

share|improve this question
    
it's been a couple months, you might want to consider accepting one of these answers. –  Bryan Oakley Mar 12 '11 at 13:44
add comment

3 Answers

def test_that_will_print_out_a_url_as_answer_for_task(sel): That should have been self.

share|improve this answer
add comment

Could it be the "sel" is missing an f?

def test_that_will_print_out_a_url_as_answer_for_task(sel):

share|improve this answer
add comment

The first step in debugging a problem like this is to assume the error message is telling the truth. Look at it literally. It says "self is not defined". So ask yourself, why isn't it defined?. There really can be only a couple reasons for that: either you genuinely didn't define it, or you think you defined it but didn't (which means a typo, or you defined it in the wrong scope)

So, where is "self" defined? In the case of python it is passed in as an argument. So, look at the argument list for that function. When you do, you'll notice that you spelled self as sel.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.