自动选择,检查下拉列表

参考网址:http://blog.csdn.net/Anniejunyan/article/details/39313591

     http://www.yiibai.com/selenium/selenium_drop_down.html

对下拉框进行操作时首先要定位到这个下拉框,new 一个Selcet对象,然后对它进行操作。 在执行上面的例子时需要导入
* org.openqa
* .selenium.support.ui.Select类。首先创建一个Select的对象,isMultiple)用来判断是否是多选下拉框
* Select类提供了3种方法来选择下拉选项
* selectByVisibleText),selectByValue),selectByIndex)。
* 在使用返些方法的时候要注意下拉列表是否是动态变化的 

如果只是单选的下拉列表,通过 getFirstSelectedOption)就可以得到所选择的项, 再调用 getText) 就可以得到本文。如果是多选的下拉列表,使用 getAllSelectedOptions) 得到所有已选择的项,此方法会返回元素的集合。 使用 assertArrayEquals)方法来对比期望和实际所选的项是否正确。 调用 getAllSelectedOptions).size)方法来判断已选的下拉列表项数量。 如果想检查某一个选项是否被择了,可以使用 assertTrueact_sel_options.contains“Red”)) 方法

我们可以用“selectByVisibleText’或’selectByIndex’或’selectByValue’的方法选择一个选项。

让我们明白,如何使用交互复选框 – http://www.calculator.net/interest-calculator.htmll。我们还可以检查下拉框中选择/启用/可见。

// Selecting an item from Drop Down list Box
	Select dropdown = new Selectdriver.findElementBy.id"ccompound")));
	dropdown.selectByVisibleText"continuously");
	
	//  you can also use dropdown.selectByIndex1) to select second element as index starts with 0.
	//  You can also use dropdown.selectByValue"annually");    
        

Published by

风君子

独自遨游何稽首 揭天掀地慰生平