Search code examples
javaseleniumwebdriverelementidentification

Selenium Webdriver - Input js/html elements identification


Have problem with identification of input elements.

For instance have two fields like this ...

<div class="col-xs-10">
  <h4>
    <a href="#" data-type="text" id="firstName" class="editable editable-click">
      Alejandroff
    </a>
  </h4>
  <h4>
    <a href="#" data-type="text" id="lastName" class="editable editable-click">
      Puchauff
    </a>
  </h4>
</div>

... which after click on eg. Name is changed to this ...

<div class="col-xs-10">
  <h4>
    <a href="#" data-type="text" id="firstName" class="editable editable-click editable-open" style="display: none;">
      Alejandroff
    </a>
    <span class="editable-container editable-inline" style="">
      <div>
        <div class="editableform-loading" style="display: none;">
        </div>
        <form class="form-inline editableform" style="">
          <div class="control-group">
            <div>
              <div class="editable-input" style="position: relative;">
                <input type="text" class="input-medium" style="padding-right: 24px;">
                <span class="editable-clear-x">
                </span>
              </div>
            </div>
            <div class="editable-error-block help-block" style="display: none;">
            </div>
          </div>
        </form>
      </div>
    </span>
  </h4>
  <h4>
    <a href="#" data-type="text" id="lastName" class="editable editable-click" style="display: inline;">
      Puchauff
    </a>
  </h4>
</div>

Till now identified Name input element like

xpath = "//*[@id="userDetails"]/div[1]/div[1]/h4[1]/span/div/form/div/div[1]/div/input

but I know it's incorrect cause it makes my test fragile (in case when dev will eg. remove one div test will fail).

Could anyone advice how to identify input in another way ?


Solution

  • Try

    "//a[@id='firstName']//following::input[@class='input-medium']"