How can I find the element in DOM based on a custom attribute?
For example:
DOM attributes are not present in HTML view. Using DOM inspector I can able to identified the Custom attribute is unique.
driver.findElement(By.id("SimpleSearch:dIndicesGrid:1:Value")).getAttribute("_celltype");
Here _celltype
is custom attribute. This attribute is not visible in HTML view.
Yes, you can use both CSS and XPATH selectors to find an element bya custom attribute.
We can find an element that contains specific text with Selenium webdriver in Python using the xpath. This locator has functions that help to verify a specific text contained within an element. The function text() in xpath is used to locate a webelement depending on the text visible on the page.
You would have to locate the element by xpath.
The following would find any element that has the _celltype attribute with value 'celltype':
driver.findElement(By.xpath("//*[@_celltype='celltype']"))
If you know what type of element it is you can make it more specific. For example, if you know they are div tags, do:
driver.findElement(By.xpath("//div[@_celltype='celltype']"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With