1

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
krishna
  • 77
  • 1
  • 10

1 Answers1

2

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)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352