简体   繁体   中英

select values from listbox in selenium webdriver not working

My below code is not working for the select values from list box. I want to select the value "Mouse" from the list.

Page factory code

@FindBy(xpath = "//select")
private WebElement lstDevice;
public WebElement lstSelectDevice() {
lstDevice.click();
new Select(lstSelectDevice()).selectByVisibleText("Mouse");
return lstDevice;

}

Page steps code

lstSelectDevice().click();

There is an error in the code where Select is initialized. The constructor of Select needs a WebElement to be passed to it. https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/Select.html

@FindBy(xpath = "//select")
private WebElement lstDevice;

public WebElement lstSelectDevice() {

    new Select(lstDevice).selectByVisibleText("Mouse");
    return lstDevice; //Not sure why u need this...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM