RE: How to Select a drop down value Based on a variable IN TestNG

How to Select a drop down value Based on a variable

I want to select a drop down  { year month  date } in Facebook Sign up page with the value from the excel sheet 

Am having a @Test method which reads the data from the Data Provider and use it in the webpage

Test(dataProvider =”excelRead” )
public void faceBook( String FirstName ,String LastName, String email, String Password, String Month, String day , String year , String sex) throws InterruptedException
{

String Month, String day , String year   – which gives the value for the dropdown to choose,
following method didn’t do anything
drp2.selectByValue(“”+day);

could you please suggest me a way to solve  this issue

esak Default Asked on July 13, 2015 in Selenium WebDriver.
Add Comment
1 Answers
Best answer

Hi, there are three different methods how to do it

driver.get(“https://www.facebook.com/”);
WebElement month = driver.findElement(By.id(“month”));
Select select = new Select(month);
select.selectByVisibleText(“Mar”);

WebElement day = driver.findElement(By.id(“day”));
Select selectDay = new Select(day);
selectDay.selectByIndex(5);

WebElement year = driver.findElement(By.id(“year”));
Select selectYear = new Select(year);
selectYear.selectByValue(“2015”);

Wait for feedback.

Reviewer Answered on July 13, 2015.

Thanks Victor  for the Valuable solution

on July 15, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.