Selenium Select - Selecting dropdown option by part of the text

前端 未结 8 1916
清歌不尽
清歌不尽 2020-12-19 16:57

The class Selenium Select has 3 methods of different option selection:

  1. selectByIndex
  2. selectByValue
  3. selectByVisibleText

Now,

8条回答
  •  余生分开走
    2020-12-19 17:26

    Get a list of all the option values and then check if the value contains your partial text. Something like this:

    List list = driver.findElements(By.tagName("option"));
    Iterator i = list.iterator();
    while(i.hasNext()) {
        WebElement wel = i.next();    
        if(wel.getText().contains("your partial text"))
        {
           //select this option
        }
    } 
    

提交回复
热议问题