如何获取数据或识别标签,即使用Selenium Java成功完成

问题描述 投票:-1回答:1
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD height="100%" vAlign=top width="86%" align=center>
<TABLE cellSpacing=0 cellPadding=0 width="80%" border=0>
<TBODY>
<TR>
<TD vAlign=top align=center>
<TABLE class=table_border_dark cellSpacing=1 cellPadding=0 width="80%" border=0>
<TBODY>
<TR align=center>
<TD bgColor=#ffffff colSpan=2>
<TABLE class=table_border_dark cellSpacing=1 cellPadding=1 width="60%" border=0>
<TBODY><LEGEND><B>Successfully Completed</B></LEGEND></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>

我尝试过:

boolean table = driver.findElement(By.xpath("//div[@id='eodProgress']/..//b[contains(text(),'EOD Process Successfully Completed')]")).isDisplayed();
System.out.println(table);

但我收到一个错误,它无法找到该元素。

java selenium xpath css-selectors webdriverwait
1个回答
0
投票

要在<b>标记中提取文本,即成功完成,您必须为visibilityOfElementLocated引入WebDriverWait,并且您可以使用以下任一解决方案:

  • cssSelectorString myText = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("TABLE.table_border_dark LEGEND>B"))).getAttribute("innerHTML");
  • xpathString myText = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//TABLE[@class='table_border_dark']//LEGEND/B"))).getAttribute("innerHTML");
© www.soinside.com 2019 - 2024. All rights reserved.