Selenium WebDriver and DropDown Boxes

前端 未结 10 1671
星月不相逢
星月不相逢 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:01

    You can use this

    (new SelectElement(driver.FindElement(By.Id(""))).SelectByText("");
    
    0 讨论(0)
  • 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<WebElement> 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");
                }       
            }
        }
    }
    
    0 讨论(0)
  • 2020-11-29 01:07

    You could try this:

    IWebElement dropDownListBox = driver.findElement(By.Id("selection"));
    SelectElement clickThis = new SelectElement(dropDownListBox);
    clickThis.SelectByText("Germany");
    
    0 讨论(0)
  • 2020-11-29 01:09

    Example for select an option from the drop down list:

    Click on drop down list by using id or csspath or xpath or name. I have used id here.

    driver.findElement(By.id("dropdownlistone")).click(); // To click on drop down list
    driver.findElement(By.linkText("india")).click(); // To select a data from the drop down list.
    
    0 讨论(0)
提交回复
热议问题