如何使用Testng选择selenium webdriver中的下拉值?

时间:2014-06-09 05:53:33

标签: selenium selenium-webdriver

我们如何使用Testng在selenium webdriver中选择下拉值?

3 个答案:

答案 0 :(得分:0)

在selenium webdriver中选择下拉列表值不是TestNG的一部分,它是selenium + java代码的一部分。

使用以下代码作为参考::

public class temp {
public static void main(String[] args) {

    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.shoppersstop.com/shoes/kids-shoes/all/brand/kittens.html");

    WebElement selectElement = driver.findElement(By
            .xpath("//select[@class='subCatThree' and @name='category']"));
    Select select = new Select(selectElement);
    List<WebElement> options = select.getOptions();

    for (WebElement option : options) {
        System.out.println(option.getText());
        if (option.getText().equals("Girls ( 3 Years & Above)")) {
            option.click();
            break;
        }
    }

}

答案 1 :(得分:0)

如果您想按值选择

Select select = new Select(driver.findelement(By.xpath("write the xpath of dropdown")));
    select.selectByValue("write value here");

如果您想按文字选择

Select select = new Select(driver.findelement(By.xpath("write the xpath of dropdown")));
    select.selectByVisibleText("write text here");

答案 2 :(得分:0)

我们如何将此代码转换为使用Selenium WebDriver

If Browser("UOB").Page("pgeSetCustomLimits").Exist(intSyncTime*1) Then
    Set oDesc=Description.Create        
    oDesc("micclass").Value = "WebElement"
    oDesc("html id").Value = "limitsInput_CI_form_label_div"
    Set ObjEle =
         Browser("UOB").Page("pgeSetCustomLimits").ChildObjects(oDesc)
    For i=0 to ObjEle.count-1
        strWebEleText = ObjEle(i).getRoProperty("innertext")
        'print strWebEleText
        If Instr(strWebEleText,strPaymentType) Then
            intRow = i
            Exit For
        End If
    Next
End If