【问题标题】:How to Click an element with attribute ROLE inside the anchor tag in Selenium?如何在 Selenium 的锚标记内单击具有属性 ROLE 的元素?
【发布时间】:2018-04-27 17:07:33
【问题描述】:

如何在 Selenium WebDriver 中使用 java 在锚标签内点击属性 role="button" 的元素?

Ex:(a="#" class="xyz "role="button")
> (span class="ABC")close(/span)
> (/a)

我只想单击此关闭按钮,但不使用跨度文本。

【问题讨论】:

    标签: selenium-webdriver


    【解决方案1】:

    使用 xpath 或 css 选择器

    Xpath - //a[@role = 'button']

    CSS - a[role = 'button']

    【讨论】:

      【解决方案2】:

      参考下面的代码,

      WebElement element = driver.findElement(By.xpath("//a[@role = 'button']"));
      JavascriptExecutor executor = (JavascriptExecutor)driver;
      executor.executeScript("arguments[0].click();", element);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-03
        相关资源
        最近更新 更多