Selenium WebDriver and DropDown Boxes

前端 未结 10 1736
星月不相逢
星月不相逢 2020-11-29 00:16

If I want to select an option of a dropdown box, there are several ways to do that. I always used:

driver.findElem         


        
10条回答
  •  执笔经年
    2020-11-29 01:02

    public static void mulptiTransfer(WebDriver driver, By dropdownID, String text, By to)
    {   
        String valuetext = null;
        WebElement element = locateElement(driver, dropdownID, 10);
        Select select = new Select(element);
        List options = element.findElements(By.tagName("option"));
        for (WebElement value: options) 
        {
            valuetext = value.getText();
            if (valuetext.equalsIgnoreCase(text))
            {
                try
                {
                    select.selectByVisibleText(valuetext);
                    locateElement(driver, to, 5).click();                           
                    break;
                }
                catch (Exception e)
                {
                    System.out.println(valuetext + "Value not found in Dropdown to Select");
                }       
            }
        }
    }
    

提交回复
热议问题