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

+2 votes
How can I get the attribute value of a web element in Selenium (either by Python or Java)?
May 15, 2019 in Selenium by Umesh
19,066 views

1 answer to this question.

+3 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")
answered May 15, 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

0 votes
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 3 in Selenium by Sri
• 2,970 points
15,576 views
0 votes
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 10, 2019 in Selenium by Sneha
12,353 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
• 27,930 points
869 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,180 points
7,170 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,520 points
3,750 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31 in Selenium by Sri
• 2,970 points
4,732 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 in Selenium by Sri
• 2,970 points
881 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,890 points
2,726 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 15, 2019 in Selenium by Pratibha
• 3,690 points
108 views