簡體   English   中英

Selenium Python腳本中的錯誤

[英]Error in Selenium Python Script

我試圖搞砸Python和Selenium RC,並且在解析下面的示例Selenium Python腳本時遇到了一些困難。 除了一個,我已經解決了以下所有代碼的錯誤:

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()

通過Selenium RC運行上述腳本后,我收到以下錯誤:


錯誤:test_that_will_print_out_a_url_as_answer_for_task( main .SignUpTask)回溯(最近一次調用最后一次):文件“/Users/eanderson/Desktop/TestFiles/Selenium1.py”,第16行,在test_that_will_print_out_a_url_as_answer_for_task self.selenium.open(“/”)NameError:global名稱'self'未定義

在24.577s中進行1次測試

失敗(錯誤= 1)


有沒有人明白為什么我得到了

NameError:未定義全局名稱“self”

第16行的錯誤,可以幫助我緩解此錯誤,以便我的腳本可以解析沒有錯誤?

def test_that_will_print_out_a_url_as_answer_for_task( sel ):那應該是self

調試這樣的問題的第一步是假設錯誤消息說實話。 從字面上看它。 它說“自我沒有定義”。 所以問問自己, 為什么不定義? 實際上只有幾個原因:要么你真的沒有定義它,要么你認為你定義它但沒有(這意味着一個錯字,或者你在錯誤的范圍內定義它)

那么,“自我”定義在哪里? 在python的情況下,它作為參數傳入。 所以,看一下該函數的參數列表。 當你這樣做,你會發現,你拼寫selfsel

可能是“sel”缺少f嗎?

def test_that_will_print_out_a_url_as_answer_for_task(sel):

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM