2014-10-23 1 views
0

콤보 상자에서 값을 선택하고 싶습니다. 나는 이것을 시도했다 :셀레늄과 자바 콤보 상자 다루는 방법

@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를 추가하려고 askes 때

내게는

+0

관련 http://stackoverflow.com/questions/11992001/how-to-get-the-selected-value-from-a-combobox-using-selenium-webdriver-selenium –

답변

1

이 시도 선언;

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; 

당신의 class.If 당신은 셀레늄 RC (예전)를 사용하여, 당신은 사용에 당신이 드라이버 변수를 추가 selenium.click 대신 selenium.select을 사용하십시오.

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

내가 전에 사용하지 않은 드라이버는 무엇인가? 나는 그것을 선언 할 수 있는가? – mohammad

+0

@mohammad Firefox를 선호하지만 ie 또는 chrome을 사용할 수 있습니다. –

+0

나는 내 질문을 더 명확하게 편집했습니다. 무엇이 드라이버 변수 – mohammad