【发布时间】:2012-05-11 23:01:57
【问题描述】:
谁能帮我将我的 xPath 转换为 CSS 选择器?我要更改的代码是这个:
String selector = "";
if(hasBaseCls()){
selector += " and contains(@class, '" + getBaseCls() + "')";
}
if(hasCls()){
selector += " and contains(@class, '" + getCls() + "')";
}
if (hasName()) {
selector += " and contains(@name,'" + getName() + "')";
}
if(hasStyle()){
selector += " and contains(@style ,'" + getStyle() + "')";
}
if(hasVisibleOption()){
selector += " and count(ancestor-or-self::*[contains(@style, 'display: none')]) = 0";
}
我正在尝试更改我的框架以使用 CSS 选择器,这是我代码中的典型构造。如果我在这个问题上看到一个有价值的答案,我想我可以管理我的大部分其他结构
【问题讨论】:
-
ancestor-or-self::*[contains(@style, 'display: none')]没有等效的 CSS。 -
我担心会出现这个答案 :( 其他的呢?或者可能是祖先或自我的解决方法?
标签: java xpath selenium automation css-selectors