Intellipaat Back

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

How can I find the element in DOM based on a custom attribute?

For example:

DOM attributes are not present in the HTML view. Using a DOM inspector I can able to identify the Custom attribute is unique.

driver.findElement(By.id("SimpleSearch:dIndicesGrid:1:Value")).getAttribute("_celltype");

Here _celltype is a custom attribute. This attribute is not visible in the HTML view.

1 Answer

0 votes
by (62.9k points)

Find the element by XPath:

WebElement element = driver.findElement(By.xpath("xpath_link")); 

xpath_link=//*[@_celltype='celltype']; // This is a sample xpath

System.out.println(element.getText());

This will get the text of the 'cell type' field and displays the value of it.

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium 3.0 certification!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...