Reputation: 329
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']
Upvotes: 0
Views: 550
Reputation: 4173
If this does not work try find a unique parent.
//div[contains(@id, 'service')]//a[contains(@id, 'inviteUsers')]
Upvotes: 0
Reputation: 473763
You can solve it with starts-with()
:
//a[starts-with(@id, "inviteUsers_")]
Upvotes: 1