Skip to main content

If there is an element above the button that is uniquely identifiable you could search only in that scope, assuming that the button is the only button in that scope. You could also try to partially match the button id (not sure if the entire thing changes, or just part of it) or match the button's class if it does not change. If there is no way to identify a unique parent or ancestor (I wouldn't know since you didn't provide the entire html), you could first find the <div id="LoginButton"><div id="LoginButton"> and then go back up from there 3 levels and then find the button under that. That xpathXPath would look like this:

//div[@id="LoginButton"]/../../../button

//div[@id="LoginButton"]/../../../button

If there is an element above the button that is uniquely identifiable you could search only in that scope, assuming that the button is the only button in that scope. You could also try to partially match the button id (not sure if the entire thing changes, or just part of it) or match the button's class if it does not change. If there is no way to identify a unique parent or ancestor (I wouldn't know since you didn't provide the entire html), you could first find the <div id="LoginButton"> and then go back up from there 3 levels and then find the button under that. That xpath would look like this:

//div[@id="LoginButton"]/../../../button

If there is an element above the button that is uniquely identifiable you could search only in that scope, assuming that the button is the only button in that scope. You could also try to partially match the button id (not sure if the entire thing changes, or just part of it) or match the button's class if it does not change. If there is no way to identify a unique parent or ancestor (I wouldn't know since you didn't provide the entire html), you could first find the <div id="LoginButton"> and then go back up from there 3 levels and then find the button under that. That XPath would look like this:

//div[@id="LoginButton"]/../../../button
Source Link
Sam Woods
  • 8.6k
  • 25
  • 43

If there is an element above the button that is uniquely identifiable you could search only in that scope, assuming that the button is the only button in that scope. You could also try to partially match the button id (not sure if the entire thing changes, or just part of it) or match the button's class if it does not change. If there is no way to identify a unique parent or ancestor (I wouldn't know since you didn't provide the entire html), you could first find the <div id="LoginButton"> and then go back up from there 3 levels and then find the button under that. That xpath would look like this:

//div[@id="LoginButton"]/../../../button