- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to extract the attribute value of an element in Selenium?
We can extract the attribute value of an element in Selenium with the help of getAttribute() method. Once we locate the element, this method is used to get the attribute value of the element and assigned to a variable.
Example
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; public class AttributeType { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); //Using id tagname attribute combination for css expression WebElement button = driver.findElement(By.cssSelector("input[name=’search’]")); // getting the type attribute and printing in console String buttontype = button.getAttribute(“type”); System.out.println(“Attribute value is “ + buttontype); driver.close(); } }
- Related Articles
- How to get an attribute value of an element in Selenium Webdriver?
- How to find an element using the attribute “id” in Selenium?
- How to find an element using the attribute “name” in Selenium?
- How to find an element using the attribute “class name” in Selenium?
- How to get attribute of element from Selenium?
- How to get the attribute value of a web element in Selenium (using Java or Python)?
- How to find an element using the attribute “HTML tag name” in Selenium?
- How to verify an attribute is present in an element using Selenium WebDriver?
- How to get an attribute value from a href link in selenium?
- Is it possible to manually set the attribute value of a Web Element using Selenium?
- Value of the class attribute node of an element in JavaScript?
- Return the value of an attribute of the selected element using CSS
- How to find an element based on a data-attribute value in jQuery?
- How to change the value of an attribute in javascript?
- How to extract the last element in an R matrix?

Advertisements