2015-11-04 82 views
2

我點擊該鏈接並獲取彈出窗口,並在彈出窗口中顯示下拉列表。 我的問題是如何從彈出窗口中選擇下拉列表中的值。如何從彈出的下拉列表中選擇數值

下面是HTML:

<select onchange="formsubmit()" id="selectedchannel" name="selectedchannel"> 
        <option value="521">Abec</option> 
        <option value="3322">Abdwdc</option> 
        <option value="1463">Abfc</option> 
        <option value="3849">Abdfc</option> 
        <option value="960">Abdfc</option> 
        </select> 
+0

彈出窗口的iframe:

driver.switchTo().frame(0); // Here 0 is index of frame , you can switch to frame by it's name also. i.e driver.switchTo().frame("your frame name"); Select option = new Select (driver.findElement(By.id("selectedchannel"))); option.selectByVisibleText("Abec"); 

可以由任何這些3個選項中選擇選項? –

+0

是的....彈出窗口是iframe –

回答

0

所以首先你必須切換到幀,然後可以選擇價值。

以這種方式選擇特定值:

option.selectByVisibleText("") // it can be Abdfc,Abec etc. 

option.selectByIndex(index) // it can be 0 ,1,2 etc 

option.selectByValue(value); //it can be 521,960 etc. 
+0

謝謝..它的工作原理:) –

+0

Great.Cheers .. :) –

相關問題