splinter - 在转储的html / screenshot中确实可见的链接奇怪的ElementNotVisible异常

时间:2014-12-31 15:49:23

标签: python html selenium selenium-webdriver splinter

我正在使用splinter运行一些浏览器测试,并且在某个时刻遇到了一个包含我想要关注的链接的页面。此调用成功并返回链接:

my_browser.find_link_by_partial_href('/mystuff/' + str(important_number))

但我无法点击它:

my_browser.find_link_by_partial_href('/mystuff/' + str(important_number)).click()
...
...
...
ElementNotVisibleException: Message: u'{"errorMessage":"Element is not currently visible and may not be manipulated","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"81","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:38495","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\\"sessionId\\": \\"7812e810-9100-11e4-881c-37067349397d\\", \\"id\\": \\":wdc:1420039695427\\"}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory":"/","path":"/click","relative":"/click","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]},"urlOriginal":"/session/7812e810-9100-11e4-881c-37067349397d/element/%3Awdc%3A1420039695427/click"}}' ; Screenshot: available via screen

这里很奇怪的是,当我关注my_browser.url时,以及当我查看my_browser.html或尝试browser.show_screenshot(my_browser)时,链接确实存在。

这似乎不是等待可见性的问题。在点击之前添加快速import time(); time.wait(5);仍然不起作用(也不再等待,尽管这可能绰绰有余)。

我可以在这里找到什么?

1 个答案:

答案 0 :(得分:1)

阿。 Splinter默认为它找到的第一个链接,它是不可见的:

(Pdb) [link.visible for link in my_browser.find_link_by_partial_href('/mystuff/' + str(important_number))]

[False, True]

这个额外的隐藏链接不应该首先出现在那里,它会告诉你如果对代码做出假设会发生什么 - 甚至是看似无关的部分!