[英]Get attribute value based on condition from other attribute in xpath element
I am trying in my JAVA code, to list all the disabled job names.我正在尝试在我的JAVA代码中列出所有禁用的作业名称。 I was trying to create an
xpath
that will list those but I could only get the Never values listed.我试图创建一个
xpath
来列出这些,但我只能列出 Never 值。
My code lists 5 Never values.我的代码列出了 5 个 Never 值。 I have 5 disabled jobs but I want to display the name of those jobs.
我有 5 个被禁用的工作,但我想显示这些工作的名称。
JAVA Code:爪哇代码:
List<WebElement> jobList = driver.
findElements(By.xpath(
"//*[contains(@class,'sectionhead expandComponentHolder')]//*[contains(@class,'scheduletime disabled')] "
)
);
Iterator<WebElement> itr = jobList.iterator();
while(itr.hasNext()) {
WebElement row = itr.next();
System.out.println(row.getText());
}
XML: XML:
<tr class = "testclass" >
<td class = "jobname" data-job-id="jobidtest" data-job-name="jobname" data-job-group="jobgroup"></td>
<td class = "scheduletime">
<span class = "scheduletime disabled" title data-toogle="tooltip" data-placemenet="auto left" data-original-title="Job schedule is disabled">
<i class ="glyphicon-time">…</i>
<span class = "detail">Never</span>
</span>
</td>
</tr>
Try using the follwing xpath expression on your xml and see if it works:尝试在您的 xml 上使用以下 xpath 表达式,看看它是否有效:
//*[contains(@class,'sectionhead expandComponentHolder')]//span[contains(@class,'scheduletime disabled')]/../preceding-sibling::td
The expression itself, on your xml above should output:上面的 xml 上的表达式本身应该输出:
jobname
工作名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.