Click the link on the URL template

I am using Selenium to do some work: the script has to click on a link followed by its own address. For example, there is a method: clickAndWait. I have to give him the title of the link. But on my page this title changes, so I need to pass the address in order to click.

could you help me?

ps I have asked this question in the selenium group but have not received an answer yet.


upd: For example, I have html code like this:

<a href="lalala.com">Some changeable title</a>
<a href="another.com">Some changeable title</a>

      

And the selenium pseudocode:

ClickAndWait('Some changeable title')

      

But I need to click on "another.com", not "lalala.com". And the name of the link changes every time. Only the link address is the same.

+2


a source to share


1 answer


You can use one of the following locators:



//use XPath to match links with full href value
selenium.clickAndWait("//a[@href='another.com']");

//use XPath to match links with href values that start with string
selenium.clickAndWait("//a[starts-with(@href,'another.com')]"); //use partial href value

//use XPath to match links with href values that contain string
selenium.clickAndWait("//a[contains(@href,'another.com')]"); //use partial href value

      

+2


a source







All Articles