A
A
Alexander2013-12-11 12:45:54
Software testing
Alexander, 2013-12-11 12:45:54

How to select an element from a generated combobox for a test on selenium (webdriver)?

Good afternoon.
There is a search string, when you enter it, for example, Novosibirsk, a list drops out. It is generated from a database of several thousand elements and displays only a few points related to Novosibirsk. The IDs of these points are always different, even if you do not refresh the page and always enter Novosibirsk, the points will be the same, but the id is different. I also need to select, for example, the first item from this list and click on it. And I can't figure out how to implement this if id as a locator is no longer suitable.

<ul id="ui-id-269" class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all" tabindex="0" style="z-index: 1; display: none; top: 290.2px; left: 859.5px; width: 361px;">
<li class="ui-menu-item" role="presentation">
<a id="ui-id-462" class="ui-corner-all" tabindex="-1">
Новосибирск
<span class="gray3">(в черте города)</span>
</a>
</li>
<li class="ui-menu-item" role="presentation">
<a id="ui-id-463" class="ui-corner-all" tabindex="-1">
</li>
<li class="ui-menu-item" role="presentation">
<a id="ui-id-464" class="ui-corner-all" tabindex="-1">
</li>

Please help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vadim Chadyuk, 2013-12-17
@twistedxtransistor

Or you can do this:
findElement(By.xpath("//li[contains(@class,'ui-menu-item') and contains(.,'Novosibirsk')]"))

E
Eugene, 2013-12-11
@Nc_Soft

You can click on an element, send a down keypress event and click again

A
alexkuzpro, 2014-07-24
@alexkuzpro

Selenium in Java has a miracle Select class that has everything you need and you can select by specific text using the method - public void selectByVisibleText(String text)
As an example

new Select(driver.findElement("селектор выпадающего списка")).selectByVisibleText("Новосибирск");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question