1
这是Splinter 0.5.4和Python 2.7.5。 Firefox 22.0,MacBook Air上运行Mountain Lion。使用Splinter运行测试时XPath无法解析链接
这是我正在尝试做的 -
1.登录到Gmail。
2.单击垃圾桶链接。
3.单击废纸篓页面中的空垃圾桶现在链接。
4.在确认对话框中单击确定。使用Firebug/FirePath - 此XPath - `// div/div [3]/div [3]/div/span`或 `// div/div [3]/div [3]/div/span [@id]` 突出显示空垃圾箱现在链接。
但是,当我运行使用分裂,XPath不解析到该链接,(,因此我得到一个AttributeError调用链接上的click()方法)。
关于为什么Splinter无法解析到链接的任何想法? 从我查过的内容来看,XPath 似乎没问题。
任何帮助,非常感谢。
def emptyTrash():
browser.click_link_by_href("https://mail.google.com/mail/u/0/?shva=1#trash")
print browser.is_element_present_by_xpath("//div/div[3]/div[3]/div/span", wait_time=5)
deleteLink = browser.find_by_xpath("//div/div[3]/div[3]/div/span[@id]")
print deleteLink #prints an empty list, since the above xpath is not finding the link
deleteLink.click() #AttributeError
trashokButton = browser.find_by_name("ok")
trashokButton.click()
将''div/div [2]/div [3]/div/span [@id]'的绝对XPath更新为更短。 –