brightpants
brightpants

Reputation: 525

XPath find a child node by class name

Ok, so I have one of those multi-auto-inputs, that for selenium requires me to enter some text in them, then wait until the list is visible and press tab.

I do this with the following code:

we.sendKeys(initialInput);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"ui-id-1\"]")));
we.sendKeys(Keys.TAB);

This is inside a method that receives a WebElement we which is the input area of the multi-auto-input.

The HTML is as follows:

<ul id="contactPersonDataWrap" class="inputAutoText tagit" data-id="contactPersonData" data-what="contactPersonDataGeneral" data-strict="1" data-max-tags="1" data-events="" data-extra-params="branchData" data-max-length="1000">
  <li class="tagit-new">
    <input class="tagit-input ui-autocomplete-input" type="text" maxlength="1000" name="contactPersonDataInput" autocomplete="off">
  </li>
    <ul id="ui-id-3" tabindex="0" class="ui-menu ui-widget ui-widget-content ui-autocomplete ui-front" style="display: none;">  
  </ul>
</ul>

This is the second one, the first is exactly the same, but the id is ui-id-1 and the name of the input is different as well.

I wanted a solution that works even in a page with N of them, that, given the WebElement for the input, I can simply wait for the list to load.

Upvotes: 0

Views: 2543

Answers (2)

Lalindra Kawshika
Lalindra Kawshika

Reputation: 313

Try this xpaths in your code:

//ul[contains(@class,'inputAutoText')]//ul[contains(@id,'ui-id')]

 //ul[contains(@class,'inputAutoText')]//ul[contains(@id,'ui-id-"+N thnumber+"')]

Upvotes: 1

Sandeep jaju
Sandeep jaju

Reputation: 84

I hope I got you correct, You need a generic xpath to identify any list after entering data.

You can have your xpath, Try this xpath:

   //ul[contains(@class,'inputAutoText')]//ul[contains(@class,'ui-autocomplete ui-front') and contains(@id,'ui-id-')]

Hope this helps.

Thank you

Upvotes: 3

Related Questions