如何在页面对象模型中初始化选择变量


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)未定义">

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

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

WebElement dropDownElement = driver.findElement(dropdownClient);
Select client = new Select(dropDownElement);

最新更新