Java 我们可以为多个可视对象创建xpath吗&;硒中的动态元素?

Java 我们可以为多个可视对象创建xpath吗&;硒中的动态元素?,java,selenium,xpath,Java,Selenium,Xpath,我想为可见元素创建一个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 St

我想为可见元素创建一个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定位器来获取特定的可见元素

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

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