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
If else for do while select in vb script?
What is vbscript?
Explain vbscript in detail?
Hello friends..... Can any give the methods for Ms-Access, and Mozilla firefox in Automation Object Model in QTP. Please give me currect answers... if you do not understand my question please don't give answers. Thanking you.
How to Enter Values on the Command promt using VB script
if u ve resrevation for train and u get a number supose 1234xxxokie.after sucessul entering all required fields. now u put that number in search and want to chk wether these ar same or not if both ar same then its okie otherwise test fail.what would be the vb script code for it to compare these two values of different page.
how to increase the values in text box in a given text box increament by two values by clicking on button
filter the array values without using filter function?
How will you check that a variable is an array in vbscript?
PLz send me the VB scripts which is having more examples my email id : hareen_11@yahoo.com
Which keyword is used to declare a variable in the vbscript language?
Which operator is used to concatenate the 2 values in the vbscript language?
What is sql loader? Explain the files used by sql loader to load file?
how to comvert 120 into one hunderd twenty rupees only and vice varsa
create a form to accept username and password validate the username and password with using message box, display the corresponding user message