2016-03-30 25 views
0

如何识别按钮单击按钮?标记是这样的:选择一个按钮 - webdriver Java

<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(); 

回答

0

您可以将ID添加到button,并使用该ID来引用它。

<button id="myButton" class="ProfileClick-actionButton js-actionButton js-actionReClick" data-modal="ProfileClick-reClick" type="button"> 
    .... 
</button> 

而且在webdriver的你会做

Actions actions = new Actions(driver); 
actions.click(driver.findElement(By.id("myButton"))).perform(); 

你需要导入org.openqa.selenium.interactions.Actions

0

您可以通过类

driver.findElement(By.className("js-actionButton")).click(); 
0

找到按钮,如下使用XPath: -

//button[@class='ProfileClick-actionButton js-actionButton js-actionReClick'] 

OR

//button[@type='button'] 

代码类似如下: -

driver.findElement(By.xpath("//button[@class='ProfileClick-actionButton js-actionButton js-actionReClick']")).click(); 

OR

driver.findElement(By.xpath("//button[@type='button']")).click(); 

希望它会帮助你:)

相关问题