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

How to open a file. What is the perpose of true and false mode there?

805


How will you get the natural logarithm of the given number in vbscript?

785


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

2577


Which operator can be used to check if two numbers are equal or not in vbscript?

860


hi i am trying for testing job for 3+ experience(fake) can u suggest me what type of projects i can keep in my resume and how much of knoeledge i should have abt that project.thnks in advance.urgt plz

2760






what do you mean .ota mobile format

2154


write a program to display configuration of a local system with the help of vb script.

1865


What are class events?

747


Explain some uses of vb script?

735


who will create the object?

1688


Which respective symbols are used to separate a line and to break the lengthy statement into multiple statements in the vbscript language?

1020


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

757


can anyone send me a vb scripts code for clicking on a link and coming back on home page again does the same for many links on a web page.

2039


does anyone have qtp11.0 license key.Please sendit to my mail id-rrvv2011@gmail.com...Thanks

2701


How to replace junk code recorded by QTP with a mall function.

1837