Selecting from div class dropdown - Selenium

后端 未结 3 778
悲哀的现实
悲哀的现实 2021-01-22 09:34

I\'m trying to select an option from a drop-down that doesnt populate until the locator has been clicked. This is what I see in Firebug:

div class=\"selectize-i         


        
3条回答
  •  不要未来只要你来
    2021-01-22 10:25

    Follow the below steps to select an item under div tag:

    You have to use collections object to store all child elements which are stored under same tag. For Ex if you have below HTML structure:

    • 2000
    • 2001
    • 2002
    • 2003
    • 2004

    Write below selenium code:

    List lst = driver.findElements(By.xpath());
    
    //In this case it is //div[@id='Year']/div/ul/li
    

    System will store all child elements in the list then you can select any element by index method using

    lst.get().click();
    

    if you do not want to find using index but text use Iterator interface to find the element from the collection then click on that element:

    Iterator it = lst.iterator();
    while (it.hasNext()) {
        WebElement wb  = it.next();
        if(wb.getText().equals()) {
            wb.click();
            break;
        }
    
    }
    

提交回复
热议问题