Computer Science, asked by navdeep1144, 1 year ago

How to get default value of dropdown in selenium webdriver?

Answers

Answered by aravinthveer006
7

Select select = new Select(driver.findElement(By.xpath("//select")));

WebElement option = select.getFirstSelectedOption();

String defaultItem = option.getText();

System.out.println(defaultItem );

Answered by Anonymous
0

The default value of dropdown in selenium web driver can be selected in the following way:

String a = driver.findElement (By. xpath ( "//select [@ id='eehdlt1']" ) ) . getText() ;

System.out.println ("The Default value selected is : " + a) ;

  • First of all, it should be checked if the accurate import statement is used on a select statement or not. The correct statement should be :

import org. openqa. selenium. support. ui. Select ;

  • A Selenium WebDriver is used to execute the testing of a web application against different web browsers.

Similar questions