开发者

Error in Selenium Python Script

开发者 https://www.devze.com 2023-02-03 08:44 出处:网络
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 erro

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 f开发者_如何学编程or 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?


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


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.


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

def test_that_will_print_out_a_url_as_answer_for_task(sel):

0

精彩评论

暂无评论...
验证码 换一张
取 消