如何识别按钮点击按钮?标记是这样的:
<button class="ProfileClick-actionButton js-actionButton js-actionReClick" data-modal="ProfileClick-reClick" type="button">
<div class="IconContainer js-tooltip" title="ReClick">
<span class="Icon Icon--reClick"></span>
<span class="u-hiddenVisually">ReClick</span>
</div>
<div class="IconTextContainer">
<span class="ProfileClick-actionCount ProfileClick-actionCount--isZero">
<span class="ProfileClick-actionCountForPresentation" aria-hidden="true"></span>
</span>
</div>
</button>
我厌倦了这个:
driver.findElement(By.className("js-actionClick")).click();
您可以向button
添加一个id,并使用该id引用它。
<button id="myButton" class="ProfileClick-actionButton js-actionButton js-actionReClick" data-modal="ProfileClick-reClick" type="button">
....
</button>
在网络驱动程序中,你可以进行
Actions actions = new Actions(driver);
actions.click(driver.findElement(By.id("myButton"))).perform();
您需要导入org.openqa.selenium.interactions.Actions
您可以按类别找到按钮
driver.findElement(By.className("js-actionButton")).click();
使用如下XPath:-
//button[@class='ProfileClick-actionButton js-actionButton js-actionReClick']
或
//button[@type='button']
代码如下:-
driver.findElement(By.xpath("//button[@class='ProfileClick-actionButton js-actionButton js-actionReClick']")).click();
或
driver.findElement(By.xpath("//button[@type='button']")).click();
希望它能帮助你:)