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
How to open a file. What is the perpose of true and false mode there?
How will you get the natural logarithm of the given number in vbscript?
write a function to read the items from combobox of Flight reservation & save in excel (QTP)??
Which operator can be used to check if two numbers are equal or not in vbscript?
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
what do you mean .ota mobile format
write a program to display configuration of a local system with the help of vb script.
What are class events?
Explain some uses of vb script?
who will create the object?
Which respective symbols are used to separate a line and to break the lengthy statement into multiple statements in the vbscript language?
Which operator is used to concatenate the 2 values in the vbscript language?
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.
does anyone have qtp11.0 license key.Please sendit to my mail id-rrvv2011@gmail.com...Thanks
How to replace junk code recorded by QTP with a mall function.