How to get the attribute value of a web element in Selenium using Java or Python

+3 votes
How can I get the attribute value of a web element in Selenium (either by Python or Java)?
May 16, 2019 in Selenium by Umesh
28,772 views

1 answer to this question.

+4 votes

Hello @Umesh, if you want to get the attributes of a web element in Selenium you can use following code snippet:

1. For Java:

driver.findElement(By.xpath(".//div[contains(@class,'value')]")).getAttribute("attr_name");

2. For Python:

driver.find_element_by_xpath("/form/div[2]/div/div[3]/center/input[2]").get_attribute("attr_name")

Check out the Selenium online training and learn more about using Java with Selenium.

answered May 16, 2019 by David
Thanks a lot, it worked for me..
Hi! Can you please upvote the answer if it has helped you!

Thanks

Related Questions In Selenium

+1 vote
2 answers

Is it possible to manually set the attribute value of a Web Element using Selenium?

WebDriver driver; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.getElementById('id123').setAttribute('attr', ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
27,475 views
+1 vote
1 answer

How to get the HTML source of a webpage using Selenium in Java?

There is a method called getPageSource() in ...READ MORE

answered Jan 11, 2019 in Selenium by Sneha
29,482 views
0 votes
1 answer

How to get coordinates of a web element using Python Selenium?

Hey Ushma, you can use following code ...READ MORE

answered Jul 29, 2019 in Selenium by Abha
• 28,140 points
3,309 views
+1 vote
2 answers

How to get the title of a webpage using Selenium Java?

Essentially, driver.getTitle(); function can be used to ...READ MORE

answered Dec 17, 2018 in Selenium by Vardhan
• 13,150 points
15,920 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,673 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,142 views
0 votes
2 answers

What is the role of TestNG & JUnit frameworks in Selenium?

TestNG and JUnit are test frameworks . it ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
2,890 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,221 views
0 votes
1 answer
0 votes
1 answer

How can I register webdrivers for python-selenium?

Hello Shelly, to register webdrivers like Chrome ...READ MORE

answered May 16, 2019 in Selenium by Pratibha
• 3,690 points
1,017 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP