Reputation: 49
I am running the script to automate test cases and found that id's keep on changing. Below is my HTML code Firebug for test drive:
<button class="G0036HC-b-a G0036HC-b-o G0036HC-b-g" id="gwt-uid-470" tabindex="0" aria-labelledby="gwt-uid-470" role="button" type="button"><div class="G0036HC-b-j">Click to continue</div></button>
Inspector:
<button class="G0036HC-b-a G0036HC-b-o G0036HC-b-g" id="gwt-uid-320" tabindex="0" aria-labelledby="gwt-uid-320" role="button" type="button"><div class="G0036HC-b-j">Click to continue</div></button>
Only id's changes. Any Help would be appreciated.
Upvotes: 2
Views: 774
Reputation: 1
use following... //input[@id=’’]/following::input[1]
You can use preceding in the same way to identify the child node
Upvotes: 0
Reputation: 176
Considering the following observations, the below code should work fine.
By.xpath("//button/div[text()='Click to continue']")
By.xpath("(//button/div[text()='Close'])[2]") # for the 2nd occurence, mind that selenium is not zero indexed
Upvotes: 0
Reputation: 16201
Besides, the answer @alecxe suggested I would also suggest you to try with text based xpath
search. I often faced issue with wait so also suggest to use explicit
wait this.
// //div[.='Click to continue']/..
By byXpath = By.xpath("//div[.='Click to continue']");
WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(byXpath));
// myDynamicElement.click();
Upvotes: 1
Reputation: 473853
You can get the element by xpath
and check that id
attribute starts with gwt-uid-
:
//button[starts-with(@id, "gwt-uid-")]
Upvotes: 1