I am trying to find an input field in a dynamic page which alters web structure mainly div and style attribute depending on number of panels opens or closes. So the Xpath given by Firepath does not help here. The input field/Text field I am trying to find has a class
class = v-textfield v-textfield-small small
but when I try to find the element with the given class name using cssSelector the driver grabs 3 similar text fields:
Just to make it easy to understand here is the html code of the panel that contains the text field.
<div id="formpanel">
...
<div class="v-absolutelayout-wrapper" style="top: 50px">Some label</div>
<div class="v-absolutelayout-wrapper" style="top: 57px">
<input class="v-textfield v-textfield-small small readonly"></input>
</div>
<div class="v-absolutelayout-wrapper" style="top: 65px">Some label2</div>
<div class="v-absolutelayout-wrapper" style="top: 69px">
<input class="v-textfield v-textfield-small small"></input>
</div>
<div class="v-absolutelayout-wrapper" style="top: 75px">Some label</div>
<div class="v-absolutelayout-wrapper" style="top: 79px">
<input class="v-textfield v-textfield-small small ws-right"></input>
</div>
</div>
I am using the following code to fill the form. But as i said it only works when style attribute matches but the page alters it depending on number of panels are opened or closed.
String style;
List<WebElement> ttN = driver.findElements(By.cssSelector("div.v-absolutelayout-wrapper"));
for(WebElement div : ttN){
style = div.getAttribute("style").toString();
if(style.equals("top: 69px")){
div.findElement(By.cssSelector("input.v-textfield.v-textfield-small.small")).sendKeys("111-Auto");
}
else if(style.equals("top: 79px")){
div.findElement(By.tagName("input.v-textfield.v-textfield-small.small.v-textfield-ws-right.ws-right")).sendKeys("5000");
}
}
Use the below xpath for same:-
//div[@class='v-absolutelayout-wrapper' and contains(.,'Some')]
This will return output as:-
1:Some label
2:Some label2
3:Some label
Use this xpath if you want only element with label2 input tag
//input[@class='v-textfield v-textfield-small small']
More specific
//div[@id='formpanel']//input[@class='v-textfield v-textfield-small small']
Hope it will help you :)