I've been looking around and trying to find a way to click on a link in selenium that's matched by a regexp.
Here is the code that works;
from selenium import selenium
sel = selenium("localhost", 4444, "*chrome", "http://www.ncbi.nlm.nih.gov/")
sel.start()
sel.open('/pubmed')
sel.type("search_term", "20032207[uid]")
sel.click("search")
sel.click("linkout-icon-unknown-vir_full")
However if I search across different IDs the link-text will be different but it always matches the regexp linkout-icon[\w-_]*
.
But I can't seem to find the right command for clicking a link which matches a regexp ... I've tried:
sel.click('link=regex:linkout-icon[\w-_]*')
sel.click('regex:linkout-icon[\w-_]*')
sel.click('link=regexp:linkout-icon[\w-_]*')
sel.click('regexp:linkout-icon[\w-_]*')
But none of them seem to work at all. Any suggestions?
EDIT:
So after comments in an answer below: The clicked item is actually an image with the id=linkout-icon-unknown-viro_full. The full line is below:
<a href="http://vir.sgmjournals.org/cgi/pmidlookup?view=long&amp;pmid=20032207" ref="PrId=3051&itool=Abstract-def&uid=20032207&nlmid=0077340&db=pubmed&log$=linkouticon" target="_blank"><img alt="Click here to read" id="linkout-icon-unknown-vir_full" border="0" src="http://www.ncbi.nlm.nih.gov/corehtml/query/egifs/http:--highwire.stanford.edu-icons-externalservices-pubmed-standard-vir_full.gif" /></a> </div>
If your wondering I got the code from the Selenium IDE recorder.