Hello, I am writing Java tests using Test NG. Faced such a problem: There is a method for selecting value from a drop-down list (see example below)

public void selectItemByValue(WebElement element, int index) { Select dropdown = new Select(element); dropdown.selectByIndex(index); } 

Here is a section of code from which I need to select one element (I need to select an employee) - http://prntscr.com/i8qrgj

When you run the test - gives an error -
'org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "div"

Can not find a solution, please help who has already encountered this. (What an error means I understand, but how to solve it is not quite)

    2 answers 2

    As I’ve already figured out, this is my Semantic drop-down list, where each choice is provided as a div ... Are there any universal methods for choosing a variant from the drop-down list of this type or is it better to use the usual methods of pressing a button and knocking an element through locators ?

      Type Select can be used only for select elements, as far as I know. Since you have a div , write your class for similar drop-down lists. Or, perhaps, there is something ready, if this thing is common.

      You can select by the data-value attribute: first click on the list so that it "falls out", and then on the element with the desired data-value