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
write a function to read the items from combobox of Flight reservation & save in excel (QTP)??
How will you get the octal value of the given number in vbscript?
How are values assigned to the variables in the vbscript language?
how to increase the values in text box in a given text box increament by two values by clicking on button
Can any one provide code for Mid(string,start[,length]). I have been asked to write code for Mid(). i.e We need to define our own function say MyMid() which should behave same like built-in Mid function
Can anyone send me a vb script function for verifying the functionality of active links on a web page
Why to use option explicit in vb script?
How to access array data?
How to assign a numeric value to a variable?
What is the difference between a dictionary and an array?
Hellow friends, I am learning QTP,but here problem is VB script. please guide me how to learn VB script w.r.t QTP and if you know any books tell me or if you have any materials or any use full material or any else w.r.t QTP please post me p.p.sekhar
What are the 2 ways in which a variable can be declared in the vbscript language?
What are the different types of loops available in the vbscript language?
Mention what is select case statement?
give me any information abou vb script books learn quckly