Selenium Java正在尝试单击按钮
我试图点击一个按钮,它有下面的HTML
<button title="XXYZ" class="clsBarButton" id="tbCodeBookI10" hidefocus="true"
onmouseover="changeTBC(this)" onmouseout="changeTBC(this)" onmousedown="changeTBC(this)"
onmouseup="changeTBC(this)" onclick="OpenReference('i10codebook'); resyncTabs();" type="button">
</button>
我在代码中尝试了以下不同的行,但它们都没有抛出这样的元素
driver.findElement(By.xpath("//button[@id='tbCodeBookI10' and class='clsBarButton2']")).click()
driver.findElement(By.cssSelector("html body.clsBody.clsAJAXBody div#Toolbar
button#tbCodeBookI10.clsBarButton")).click();
# 1 楼答案
这应该很好用
如果它像您在评论中建议的那样继续失败,请检查两件事,HTML是有效的HTML,并且您的按钮不在iframe中(在这种情况下,您首先需要切换到iframe)
要切换到iframe,以下代码应该可以工作