Unable to get the selected text value from the drop down | Selenium Training|Java|WebDriver|TestNG|Frameworks|Videos

Unable to get the selected text value from the drop down

T
Tanuj Post on 25/11/2019

There is a drop down in that selected any index value using "selectedbyindex(i)" now i need the value which i selected in drop down to validate the value. Please let me know how we can achieve this thing.

Find the set of code

WebElement dropdown = driver.findElement(By.id("portfolioid"));

Select s = new Select(dropdown);

s.selectByVisibleText("My Portfolio");

s.selectByIndex(2);
// System.out.println(s.getFirstSelectedOption()); 

S

Instructor

Support Team Reply on 25/11/2019

Before this... can you put a delay of 5 sec?

Thread.sleep(5000)

Select s = new Select(dropdown);

T
Tanuj Reply on 25/11/2019

Hi Team,

Thanks for quick response.

I am able to select the value from drop down but after selection how we can get it selected text means what value currently selected?

 

Eg :

WebElement dropdown = driver.findElement(By.id("portfolioid"));

Select s = new Select(dropdown);

s.selectByVisibleText("My Portfolio");

s.selectByIndex(2);

After above line how we can get the selected drop down value?

 

T
Tanuj Reply on 26/11/2019

Any Update?

S

Instructor

Support Team Reply on 27/11/2019

 

s.getFirstSelectedOption()

 

will give you currently selected Option