-2

How can we select the dropdown value in selenium webdriver using Testng?

2
  • There aren't enough details in your post for us to help you. Please add HTML for the dropdown, or a link to the website with the dropdown. Also include what you have tried so far. Commented Jun 9, 2014 at 5:58
  • refer this : santoshsarmajv.blogspot.in/2013/04/Select.html Commented Jun 9, 2014 at 8:02

3 Answers 3

0

Selecting dropdown values in selenium webdriver is not a part of TestNG, it's part of selenium+java code.

Use below code for reference ::

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;
        }
    }

}
Sign up to request clarification or add additional context in comments.

Comments

0

If you want to select by value

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

If you want to select by Text

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

1 Comment

Please add selectByIndex as well to your answer.
0

How do we convert this code to use 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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.