![](/img/trans.png)
[英]Choose an item from Combo box in Selenium Webdriver with Java
[英]Selenium with Java how to deal with combo box
我想從組合框中選擇一個值。 我嘗試了這個:
@Test(enabled = true)
public void hierarchyLegendArea() throws Exception {
setUp(Constants.BASE_URL_NAME, "chrome");
selenium.setSpeed("1500");
selenium.open(Constants.OPEN_NMA_TEMPLATE_DIR);
selenium.windowMaximize();
Thread.sleep(15000);
String comboBoxId = "//*[@id=\"contentTopBarCombobox\"]/div/div[1]/div[2]";
String valueInSideComboBoxId ="combo_box_values_cachable";
selenium.click(comboBoxId);
Thread.sleep(1000);
selenium.click(valueInSideComboBoxId);
}
但這沒有用。 有誰知道如何從組合框中選擇一個值?
當我嘗試添加驅動程序變量eclips要求我進行聲明時
嘗試這個;
WebDriver driver = new FirefoxDriver();
Select dropDown = new Select(driver.findElement(By.id("contentTopBarCombobox")));
dropDown.selectByValue("yourValue");
要么
WebDriver driver = new FirefoxDriver();
Select dropDown = new Select(driver.findElement(By.id("contentTopBarCombobox")));
dropDown.selectByIndex(1);//choose your value index, for example I choose index 1.
您需要導入
import org.openqa.selenium.WebDriver;
在類中添加驅動程序變量時。如果使用selenium rc(舊的),則使用selenium.select
而不是selenium.click
參見
selenium.select("yourComboName", "label=yourValue");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.