How to select a value from a list box by using Selenium
web-driver?

Answers were Sorted based on User's Feedback



How to select a value from a list box by using Selenium web-driver?..

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

How to select a value from a list box by using Selenium web-driver?..

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

Post New Answer

More VB Script Interview Questions

a;;b;c;;;d in this string output is abcd will come how can we do that in vbscript in QTP testing?

2 Answers  


What are the environments supported by vbscript language?

0 Answers  


hi Set myobj=Description.Create() myobj("type").value="submit" myobj("name").value="google search" myobj("html tag").value="button" browser("title:=google").page("title:=google").webButton (myobj).Click i was running above code in one weak back it was working fine i got result,again i opened after few days ,again i was trying to run the code it shows run time error in last line of my code ,why ?pls answer my question?

0 Answers  


Plzzzzzzz can any one tell me which is the best institute in hyderabad for learing VBScript. plz do answer guys its urgent plzzzzzzz. thanks in advance.

0 Answers  


Which event is triggered when mouse focus comes out of an element in the vbscript language?

0 Answers  






What is the difference between javascript and vbscript?

0 Answers  


Why do we use Option Explicit?

6 Answers  


Can anyone help me in write coding to get this pattern * ** *** ****

3 Answers  


What is the difference between a dictionary and an array?

0 Answers  


How to open a file. What is the perpose of true and false mode there?

0 Answers  


Hi Friends Rajendra this is bhavani prasad, iam working Hyderabad. i faced one problem with qtp recording mode i.e in my application there is 100 records first we click the first record that record will be jumped to next session and 99 records will there stop the recording and run the same script .Run this script qtp does not identify the records. So plz tell me what is the solution.

0 Answers  


please can you help me to get a code of flames using a visual basic 6

0 Answers  


Categories