如何初始化页面对象模型中的Select变量

问题描述 投票:0回答:1
By user_ID = By.name("txtUserID");
By pwd = By.name("txtPassword");
By Login = By.xpath("//button[contains(text(),'Log In')]");
By dropdownclient = By.xpath("//select[@id='selClientSelect']");

public void select_client()
    {   

        Select client = new Select(dropdownclient);
        client.selectByValue("1");
    }

但是我遇到错误“构造函数Select(By)未定义”]

java selenium dropdown
1个回答
0
投票

确保已导入选择:import org.openqa.selenium.support.ui.Select;

您还需要初始化WebElement,然后才能将其传递到Select构造函数中:

WebElement dropDownElement = driver.findElement(dropdownClient);
Select client = new Select(dropDownElement);
© www.soinside.com 2019 - 2024. All rights reserved.