TestProject Forum
Powered by leading experts in the test automation community

Identify button element with no ID / class name

What would be the ideal way to identify a button without id or class ?

Sample

You could try by xpath, using the text of the button for identifier:

By.xpath("//button[contains(., 'Sample')]")

It’s basically the same as:

By.xpath("//button[contains(text(), 'Sample')]")

So I’ll just have to locate with inner html. I guess that works as well.

Thanks for the assist