Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

I'm working with Selenium in Python. I would like to get the .val() of an <select> element and check that it is what I expect.

This is my code:

def test_chart_renders_from_url(self):

    url = 'http://localhost:8000/analyse/'

    self.browser.get(url)

    org = driver.find_element_by_id('org')

    # Find the value of org?

How can I do this? The Selenium docs seem to have plenty about selecting elements but nothing about attributes.

1 Answer

0 votes
by (50.2k points)

For this get_attribute(name) might do the job

For get_attribute here is an example through which you will get to know how to implement

def test_chart_renders_from_url(self):

    url = 'http://localhost:8000/analyse/'

    self.browser.get(url)

    org = driver.find_element_by_id('org')

    # Find the value of org?

    val = org.get_attribute("attribute name")

Refer: https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.get_attribute

If you wish to Learn Selenium visit this Selenium Certification by Intellipaat.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers

500 comments

108k users

Browse Categories

...