1

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:

  1. "v-textfield v-textfield-small small readonly"
  2. "v-textfield v-textfield-small small ws-right"
  3. "v-textfield v-textfield-small small"

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");
}
}
Anas Asif
  • 35
  • 6

3 Answers3

1

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 :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • I m trying to get the field with the class: v-textfield v-textfield-small small if i just code: div.findElement(By.cssSelector("input.v-textfield.v-textfield-small.small")).sendKeys("111-Auto"); it grabs the wrong inputfield – Anas Asif Oct 09 '15 at 11:39
  • then what's the problem with //input[@class='v-textfield v-textfield-small small'] – Shubham Jain Oct 09 '15 at 11:58
  • wc @AnasAsif ... feel free to vote up .. it will really help me .. thanks :) – Shubham Jain Oct 09 '15 at 12:45
0

You can use following Xpaths:

//input[@class='v-textfield v-textfield-small small readonly']
//input[@class='v-textfield v-textfield-small small']
//input[@class='v-textfield v-textfield-small small ws-right']
Atin
  • 380
  • 1
  • 5
  • 10
  • If i use the second xpath you mentioned. Then its giving me isDisplayed() false. Probably its grabbing all 3 by that again. The rest of the 2 worked – Anas Asif Oct 09 '15 at 12:34
0

Try:

.v-textfield.v-textfield-small.small:not(.readonly):not(.ws-right)
TEH EMPRAH
  • 1,828
  • 16
  • 32