String city;
Select dropdown = new Select(driver.findElement(By.id("city"))); //Selects the dropdown menu
dropdown.selectByValue(cityName); //selects Ajax as the city from the Dropdown menu
city = dropdown.selectByValue(cityName);
这就是我正在使用的。但它不起作用。请帮帮我。
答案 0 :(得分:0)
如果您想从下拉列表中获取当前选定的文字,可以使用' getFirstSelectedOption'方法,如下图所示:
String city;
Select dropdown = new Select(driver.findElement(By.id("city"))); //Selects the dropdown menu
dropdown.selectByValue(cityName); //selects Ajax as the city from the Dropdown menu
city = dropdown.getFirstSelectedOption();
如果我误解了你的问题,请告诉我。