Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium与Java如何处理组合框_Java_Selenium - Fatal编程技术网

Selenium与Java如何处理组合框

Selenium与Java如何处理组合框,java,selenium,Java,Selenium,我想从组合框中选择一个值。 我试过这个: @Test(enabled = true) public void hierarchyLegendArea() throws Exception { setUp(Constants.BASE_URL_NAME, "chrome"); selenium.setSpeed("1500"); selenium.open(Constants.OPEN_NMA_TEMPLATE_DIR); s

我想从组合框中选择一个值。 我试过这个:

@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");

你需要导入这个

import org.openqa.selenium.WebDriver;
在类中添加驱动程序变量时。如果使用selenium rc(旧的),则使用
selenium。选择
而不是
selenium。单击
。请参阅

selenium.select("yourComboName", "label=yourValue"); 

相关什么是驱动程序?我以前从未使用过它,如何声明它?@mohammad我更喜欢Firefox,但你可以使用ie或chrome。我编辑了我的问题,以便更清楚地说明什么是驱动程序variable@mohammad驱动程序是org.openqa.selenium.WebDriver,请参阅
selenium.select("yourComboName", "label=yourValue");