Selenium Select - Selecting dropdown option by part of the text

前端 未结 8 1859
清歌不尽
清歌不尽 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:29

    You can try a logic like this hope this helps

    List  optionsInnerText= driver.findElements(By.tagName("option"));
    for(WebElement text: optionsInnerText){
        String textContent = text.getAttribute("textContent");
        if(textContent.toLowerCase.contains(expectedText.toLowerCase))
               select.selectByPartOfVisibleText(expectedText);
        }
    }
    

提交回复
热议问题