如何在div中使用 selenium 元素查找元素按钮?

e0bqpujr  于 2022-11-24  发布在  其他
关注(0)|答案(2)|浏览(110)

我有三个〈div class= emploBox“〉,每个都有一个按钮。按钮没有唯一的名称。我如何找到这个特定的按钮?我想使用class=cutTooLongTest并测试”自动测试器“,但我不知道如何操作。我想找到标记为黄色的按钮。
enter image description here
我不知道解决办法

chy5wohz

chy5wohz1#

如果我没理解错的话,您需要使用文本“automated tester”找到按钮的XPath。
XPath表达式应如下所示:

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

qgelzfjb2#

这应该对您有效:

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

相关问题