How to use select list in selenium?

前端 未结 4 1986
说谎
说谎 2020-12-20 12:58

I\'m trying to select an element from a select list in selenium using java with WebDriver - based syntax.

I\'ve got the select list by

    elements =         


        
4条回答
  •  梦毁少年i
    2020-12-20 13:49

    Try to do it like this :

    //method to select an element from the dropdown

    public void selectDropDown(String Value) {

        webElement findDropDown=driver.findElements(By.id="SelectDropDowm");
        wait.until(ExpectedConditions.visibilityOf(findDropDown));
        super.highlightElement(findDropDown);
        new Select(findDropDown).selectByVisibleText(Value);
    }
    

    //method to highlight the element

    public void highlightElement(WebElement element) {

        for (int i = 0; i < 2; i++) {
    
            JavascriptExecutor js = (JavascriptExecutor) this.getDriver();
            js.executeScript(
                    "arguments[0].setAttribute('style', arguments[1]);",
                    element, "color: yellow; border: 3px solid yellow;");
            js.executeScript(
                    "arguments[0].setAttribute('style', arguments[1]);",
                    element, "");
    
        }
    
    }
    

提交回复
热议问题