Selenium Webdriver(C#)-基于属性的查找按钮 [英] Selenium webdriver (c#) - Finding button based on attribute

查看:233
本文介绍了Selenium Webdriver(C#)-基于属性的查找按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于属性gl-command在下面的按钮上获取一个句柄.我知道我可以使用定位器的Cssselector查找按钮,但是在这种情况下,我不想这样做.

I'm trying to get a handle on the button below based on the attribute gl-command. I'm aware I can find the button using a Cssselector by locator but I don't want to do that in this case.

我应该指出,这只是AUT中许多按钮之一:<google-componentbutton size="32"></google-componentbutton>

I should point out that this is just one of many buttons within the AUT: <google-componentbutton size="32"></google-componentbutton>

<div class="gl-component-buttons"><gl-component-buttons id="gl-component-button-set-bottom">
  <google-componentbutton size="32">
    <button class="google-componentbutton glmdl-button glmdl-js-button glmdl-js-ripple-effect google-image gl-transaction-image" style="height: 32px; widgl: 32px; background-size: 24px 24px; background-position: 4px 4px;" gl-tooltip-id="google_component_transaction" gl-tooltip="transaction" data-upgraded=",MaterialButton,MaterialRipple" gl-command="transaction">  
      <span class="glmdl-button__ripple-container">
        <span class="glmdl-ripple"></span>
      </span>
    </button>
  </google-componentbutton>

推荐答案

基于属性"gl-command"使用xpath

use xpath for based on the attribute "gl-command"

driver.FindElement(By.XPath("//*[@gl-command='transaction']")).Click();

这篇关于Selenium Webdriver(C#)-基于属性的查找按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆