2016-03-30 3 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

Вы можете добавить идентификатор к button, и использовать этот идентификатор для ссылки на него.

<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'] 

ИЛИ

//button[@type='button'] 

код что-то вроде ниже: -

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

ИЛИ

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

Надеется, что это поможет :)

Смежные вопросы