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

Mention what is vbscript?

0 Answers  


What are class events?

0 Answers  


How to create a function in vbscript?

0 Answers  


How to write a general script which should does the following a). If a page object is given, it should identify the page object of the corresponding page(site). b). It should identify all the links of that particular page. in QTP tool?

2 Answers   IBM, Infosys, Wipro,


What are the differences between Visual Basic, VBA and VBScript? When would it be appropriate to use one as opposed to another?

1 Answers   Infosys,






write a vb script to generate hello 5 times using do until loop

4 Answers  


Explain the difference between POST and GET Method.

1 Answers  


What is event handling in vbscript?

0 Answers  


What is the main difference between function and sub-procedure?

0 Answers  


What is the equivalent of VBScript?s On Error In Jscript ?

1 Answers   Microsoft,


write a function to read the items from combobox of Flight reservation & save in excel (QTP)??

0 Answers  


Write a Program to add 2 numbers without using operators (+,-) and without using third variable. Note: Use VBScript only Hint: You can use other operators like '/' & '*'(Division & Multiplication)

0 Answers   Quest,


Categories