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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / elite

We need to get all options using String[] options = Selenium.getSelectOptions
and use selenium.select(options[2]) which will select second option

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More VB Script Interview Questions

which is the best institute in banglaore for software testing?

1 Answers  


plz give ans to this in vb script........ "krishna radha" i want to print this string "Radha Krishna" like this

5 Answers  


1. How to handle object implementation change in DP for Ex: i have login page with username,pasword (editboxes),login,cancel(buttons). Here i written DP code for login page with the help properties. My questions: 1.If properites are changing dynamically i will do (i want code for that) 2.if objects are changed dynamcally i will do (i wnat code for that)

0 Answers   iFlex,


what is the differenece btwn scripting language and programming language

4 Answers  


How to scroll down a page while recording in qtp. suggest me any method apart from low level recording.

0 Answers  






What is the difference between function and procedure?

0 Answers  


What are the environments supported by vbscript language?

0 Answers  


How to create MSAcess table foriegn key

1 Answers  


accept a string & display whether a is present or not

1 Answers  


Explain the scope of the variables using dim, public, and private keywords respectively.

0 Answers  


How should i Create Email invite with server-side Coding?

0 Answers   Altair,


Like OPTION EXPLICIT statement what are the other statements used in vbscript and their usage. Please post me all the statements please.

0 Answers   Accenture,


Categories