Monday 5 May 2014

Clicking the webelement with dynamic ID

Clicking the web Element with Dynamic ID

Scenario:


If the webelement is keep on changing on each page load(If Particular char been not changing) , we can handle by "Contains" Keyword in element finder.

For Eg.

First time the ID of the element is "Button_1", then some other time it changing randomly "Button_3", "Button_45".. etc

By Using below code we can click the Button:

driver.findElement(By.xpath(//*[contains(@id,'Button_')])).click();