How to select a value from a list box by using Selenium
web-driver?
Answers were Sorted based on User's Feedback
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 |
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 |
can anyone tell me the procedure of interview held in applabs
How to map test cases with Automation script? Please explain in details.With example Thanks for your co-operation(In Advance)
generic function for webedit box for web application
What purpose does ‘on error resume next’ serves?
How do you get the value of a combo box in Javascript?
How will you get a random number between 0 and 1 in vbscript?
plz give ans to this in vb script........ "krishna radha" i want to print this string "Radha Krishna" like this
What is the use of the ‘open’ method to work with the database in the vbscript language and what connection string is passed in the same and what is its usage?
How to assign a date value to a variable?
write any ttest cases using check points and parameterization
what is used of Property........End Property loop ? how to write the script for it?
Input = 124 output should be 124421 Please do not use any string functions/variables