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 |
best training centre in bangalore
Write a program to create a Dynamic array of size 5 elements and display all the elements.
In html file what is an ideal position to include vbscript?
what does create object actually do when you call it in vbscript?
after medical test,when will be the police verification
hi what is called GUI in QTP 8.2 and how can we test the apllication using GUI?
How can you test font size, type and color using QTP tool?
How will you get the exponent of the given number in vbscript?
Differentiate javascript and vbscript?
Explain the arrays in vb script?
why variable name should not exceed 255 characters?
Mention how to access array data?