Home > OS >  how to find element button in div using selenium?
how to find element button in div using selenium?

Time:11-16

I have three <div class= emploBox "> and each has a button. Buttons do not have unique names. How can I find this particular button? I want to use class=cutTooLongTest and test 'automated tester' but I don't know how. wants to find the button marked in yellow.

enter image description here

I have no idea for a solution

CodePudding user response:

If I understood you right, you need to find the XPath for the button using the text 'automated tester'.

The XPath expression should be like this:

//h2[text() = 'automated tester']//..//button[contains(@class, 'standard Button--icon')]

CodePudding user response:

this should work for you:

webDriver.findElement(By.xpath("//h2[@class = 'cutTooLongTest' and text() = 'automated tester']/following-sibling::div/button[1]"));
  • Related