【问题标题】:Can we create an xpath for multiple visible & dynamic elements in Selenium?我们可以为 Selenium 中的多个可见和动态元素创建一个 xpath 吗?
【发布时间】:2020-05-12 08:59:52
【问题描述】:

我想为可见元素创建一个 XPath。我尝试了这两种技术。

1. By locator = By.xpath("//a[contains(@style, 'display: none')]")
// It gives the elements those are hidden by display: none property.

2. driver.findElement(locatorXPath).isDisplayed();
// It can throw exceptions like StaleElementException as locatorXPath is the locator for dynamic content i.e. loading icon.`

有什么方法可以创建 XPath 定位器来获取特定的可见元素?

【问题讨论】:

    标签: java selenium xpath


    【解决方案1】:

    您不能为可见/不可见元素创建 XPath。如果元素具有相应的属性,您的第一次尝试将返回您。然而,这种情况很少发生。在大多数情况下,样式是通过 CSS 表分配的。

    XPath 是关于 DOM 结构的,而不是关于样式的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 2019-09-27
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      • 2010-09-07
      相关资源
      最近更新 更多