krishna
krishna

Reputation: 77

Get selected value from drop down selenium python

I am new to selenium I want get the selected option value from drop down button after selection are made here I tried with something but i did not get expected result

exams=Select(driver.find_element_by_id("exam"))
option1=exams.first_selected_option
print("option 1    ->   ",option1)

output is

option 1 -> <selenium.webdriver.remote.webelement.WebElement (session="caa3498bece769cdcc9db1143e54c516", element="18ba0158-5c50-4d67-88e4-466bc6dacc67")>

in java getText() is used to get the value. is there any similar method available in python

Upvotes: 1

Views: 82

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193078

Instead of printing the WebElement option1, you need to print the WebElement's text attribute.

So effectively you need to replace:

print("option 1    ->   ",option1)

With:

print("option 1    ->   ",option1.text)

Upvotes: 2

Related Questions