|
需求:打开某个页面,该页面有很多静态链接,需要校验这些link是否正确(能正常打开不显示404或者其他提示信息即可)。这些link会定期更新。
自己写的代码:
# link to the first sponsor link in the sidebar(用xpath定位页面的link区域,不止一个link)
link_xpath = "div[2]/div[2]/div[2]/div/div/h1"
# selenium doesn't support opening links in a new window. So will open the url directly.
# first get the url
url = sel.get_attribute(link_xpath + "/@href")
# then open the page
sel.open(url)
# make sure we are not seeing an error
self.assertTrue(sel.get_title().find(u"500内部服务器错误") < 0)
运行总报错:
File "d:\daodao\dealhome.py", line 25, in test_untitled
url = sel.get_attribute(link_xpath + "/@href")
File "C:\Python26\lib\site-packages\selenium-2.0_dev_9341-py2.6.egg\selenium\s
lenium\selenium.py", line 1339, in get_attribute
return self.get_string("getAttribute", [attributeLocator,])
File "C:\Python26\lib\site-packages\selenium-2.0_dev_9341-py2.6.egg\selenium\s
lenium\selenium.py", line 216, in get_string
result = self.do_command(verb, args)
File "C:\Python26\lib\site-packages\selenium-2.0_dev_9341-py2.6.egg\selenium\s
lenium\selenium.py", line 212, in do_command
raise Exception, data
xception: ERROR: Element /html/body/div[2]/div[2]/div[2]/div/div/h1/ not found
---------------------------------------------------------------------
个人分析,我感觉是xpath定位有问题,各位大侠帮忙看看,感谢 |
|