Selenium Python Script Issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Erik Anderson
    New Member
    • Jan 2011
    • 1

    Selenium Python Script Issue

    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

    Code:
    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()
    I run the Python script and then get the following error:
    =============== =============== =============== =============== ==========
    ERROR: test_that_will_ print_out_a_url _as_answer_for_ task (__main__.SignU pTask)
    ----------------------------------------------------------------------
    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.o pen("/")
    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
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    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)

    Comment

    Working...