How can we select the dropdown value in selenium webdriver using Testng?
Asked
Active
Viewed 3,894 times
-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. – Richard Jun 09 '14 at 05:58
-
refer this : http://santoshsarmajv.blogspot.in/2013/04/Select.html – Santoshsarma Jun 09 '14 at 08:02
3 Answers
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;
}
}
}

Anand Somani
- 801
- 1
- 6
- 15
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");

Gaurav
- 85
- 4
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

Archimedes Trajano
- 35,625
- 19
- 175
- 265

kuldeep
- 1