views:

111

answers:

1

Hello, I'm using Selenium for making some work: script should click at link followed by it's own address. For example, there is a method: clickAndWait. I have to pass it link title. But at my page this title changes, so I have to pass address to click at.

Could you help me with this?

p.s. I asked this question in selenium group, but still have no answer.


upd: For exampe, I have such html-code:

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

And selenium pseudocode:

ClickAndWait('Some changeable title')

But I have to click at site 'another.com', not 'lalala.com'. And link's title changes every time. Only link address is the same.

+1  A: 

You could 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
Dave Hunt
Great! Thank you.
Ockonal
Check, please, your code. There should be second '[' -> ']' otherwise it won't work. For example: ("//a[contains(@href,'another.com')]");
Ockonal
Thanks. Updated my answer.
Dave Hunt
And another one small question: how can I click at second fount link? (I use your 3rd sample). I tried somethinkg like [2] at the end of the command, or /[2]. This won't work for me =) Thanks.
Ockonal
Try `//body/descendant::a[contains(@href,'another.com')][2]`
Dave Hunt
Thanks, have no more questions.
Ockonal