I am running some browser tests with splinter and, at one point, come across a page with a link I want to follow. This call succeeds and returns the link:
my_browser.find_link_by_partial_href('/mystuff/' + str(important_number))
But I cannot click it:
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
What's odd here is that the link is indeed present when I follow my_browser.url
, as well as if I look at my_browser.html
or trybrowser.show_screenshot(my_browser)
.
And it doesn't seem to be an issue of waiting for visibility. Adding a quick import time(); time.wait(5);
before the click still doesn't work (nor do longer waits, though that's probably more than sufficient).
What could I be missing here?
Ah. Splinter is defaulting to the first link it finds, which isn't visible:
(Pdb) [link.visible for link in my_browser.find_link_by_partial_href('/mystuff/' + str(important_number))]
[False, True]
This extra hidden link isn't supposed to be there in the first place, which goes to show you what can happen if you make assumptions about your code - even the seemingly irrelevant parts!