【发布时间】:2011-01-11 07:46:42
【问题描述】:
我正在尝试掌握 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:未定义全局名称“self”
在 24.577 秒内运行 1 次测试
失败(错误=1)
有没有人明白我为什么会得到这个
NameError:未定义全局名称“self”
第 16 行的错误,可以帮助我缓解此错误,以便我的脚本可以无错误地解析吗?
【问题讨论】:
标签: python error-handling selenium selenium-rc