How to select a value from a list box by using Selenium
web-driver?

Answer Posted / mahendra

public static void m1()
{//intantiate webdriver
WebDriver driver = new FirefoxDriver();
//open the browser
driver.get("http://www.lanoie.net/classes/XHTML/forms/lectures/lecture8_1.html");
//frist get the webelement of select tag
WebElement sele=
driver.findElement(By.xpath("//html/body/div/div[1]/div/form[3]/p[1]/select"));
//instantiate select class with that webelement
Select select=new Select(sele);
//get all value into list
//select.selectByValue("Modem 33.6 Kbps");
select.selectByVisibleText("Modem 33.6 Kbps");
select.selectByIndex(4);
WebElement
selectm=driver.findElement(By.xpath("html/body/div/div[1]/div/form[2]/p/select"));
Select selet = new Select(selectm);
//selet.selectByIndex(3);Or
//selet.selectByVisibleText("Netscape 4");or
//selet.selectByValue(“mahendra”)or
List<WebElement> options=select.getOptions();
for(WebElement option : options)
{if (option.getText().equals("T-1"))
{
option.click();
}
}

}

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If else for do while select in vb script?

645


What is vbscript?

600


Explain vbscript in detail?

617


Hello friends..... Can any give the methods for Ms-Access, and Mozilla firefox in Automation Object Model in QTP. Please give me currect answers... if you do not understand my question please don't give answers. Thanking you.

1852


How to Enter Values on the Command promt using VB script

1534






if u ve resrevation for train and u get a number supose 1234xxxokie.after sucessul entering all required fields. now u put that number in search and want to chk wether these ar same or not if both ar same then its okie otherwise test fail.what would be the vb script code for it to compare these two values of different page.

1444


how to increase the values in text box in a given text box increament by two values by clicking on button

1648


filter the array values without using filter function?

1657


How will you check that a variable is an array in vbscript?

546


PLz send me the VB scripts which is having more examples my email id : hareen_11@yahoo.com

1667


Which keyword is used to declare a variable in the vbscript language?

533


Which operator is used to concatenate the 2 values in the vbscript language?

560


What is sql loader? Explain the files used by sql loader to load file?

624


how to comvert 120 into one hunderd twenty rupees only and vice varsa

1807


create a form to accept username and password validate the username and password with using message box, display the corresponding user message

2163