0

Trying to find an xpath expression to use in:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("XPATH HERE"))).click();

The element says "Invite Users" on the page and i need to be able to click on it

I need to find the element /a[@id='inviteUsers_8ef17ba4-b739-4fb6-8198-3862ea84c381_toggle'] but the problem is the characters after "inviteUsers_" is dynamically generated

I have already tried these:

"//*[contains(.,'Invite Users')]";
"//a[contains(.,'Invite Users')]";

And these give NoSuchElement exceptions.

This is the complete XPATH:

/html/body/div[@class='col-xs-10 col-xs-offset-2 main']/fieldset[@class='form-horizontal']/div[@id='roles']/div[@id='entitlements']/div[@class='panel panel-default '][3]/div[@id='service_8ef17ba4-b739-4fb6-8198-3862ea84c381']/div[@class='panel-body']/div[@class='panel panel-default'][1]/div[@class='panel-heading']/h4[@class='panel-title']/a[@id='inviteUsers_8ef17ba4-b739-4fb6-8198-3862ea84c381_toggle'] 
1
  • Did you find your answer? If not, please post the relevant HTML for the link you are trying to click. Commented Jul 11, 2016 at 4:23

2 Answers 2

1

You can solve it with starts-with():

//a[starts-with(@id, "inviteUsers_")]
Sign up to request clarification or add additional context in comments.

16 Comments

Still failed to find the element unfortunately :( Am i missing something from the xpath ? Maybe i need to get a specific div before trying to access the element ?
@shanwar no, if it fails like that, it would fail with a specific div as well. Is this a public page and you can share a link to it? Thanks.
Unable to do that sorry. Confidential page under development. Could it be that this element appears in sort of like a drop down area after a subsequent click of a previous element so it fails? I would think the wait (7sec before timeout) takes care of that...
@shanwar could be all sorts of things happening, difficult to say what is it exactly. Could you post how this element looks in the HTML? Also, make sure you make all the necessary actions for that element to appear.
Watching Selenium execute the test(with debugger) I can see that it execute until the point where it tries to find that element
|
0

If this does not work try find a unique parent.

//div[contains(@id, 'service')]//a[contains(@id, 'inviteUsers')]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.