close

How to get attribute of element from Selenium?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to get attribute of element from Selenium in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to get attribute of element from Selenium?

  1. How to get attribute of element from Selenium?

    You are probably looking for get_attribute(). An example is shown here as well
    def test_chart_renders_from_url(self): url = 'http://localhost:8000/analyse/'

  2. get attribute of element from Selenium

    You are probably looking for get_attribute(). An example is shown here as well
    def test_chart_renders_from_url(self): url = 'http://localhost:8000/analyse/'

Method 1

You are probably looking for get_attribute(). An example is shown here as well

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")

Method 2

Python

element.get_attribute("attribute name")

Java

element.getAttribute("attribute name")

Ruby

element.attribute("attribute name")

C#

element.GetAttribute("attribute name");

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read