How can we select the dropdown value in selenium webdriver using Testng?
-
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– Richard2014-06-09 05:58:20 +00:00Commented Jun 9, 2014 at 5:58
-
refer this : santoshsarmajv.blogspot.in/2013/04/Select.htmlSantoshsarma– Santoshsarma2014-06-09 08:02:34 +00:00Commented Jun 9, 2014 at 8:02
Add a comment
|
3 Answers
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;
}
}
}
Comments
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
LittlePanda
Please add
selectByIndex as well to your answer.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