如何使用下面的html代码中的selenium / python找到以下文本(没有ID,没有名称或引用)。 上述文本仅在满足特定条件后出现(文件上传成功) 请参阅下面的部分html代码,此文本位于2个表之间,link provided
中的完整代码我要找的所需文字:
PCA提交请求已成功完成
部分HTML代码:
<TABLE border=0 cellpadding=0 cellspacing=3>
<TR>
<TD class=label width=20%>Contract Number:</TD>
<TD width=25% class=fieldlabel>20003171</TD>
<TD class=label width=20%>Separable Portion:</TD>
<TD width=25% class=fieldlabel>30071948</TD>
</TR>
<TR>
<TD class=label>Work Order:</TD>
<TD class=fieldlabel>1</TD>
</TR>
<TR>
<TD class=label>Title:</TD>
<TD class=fieldlabel colspan=3>(NSW) Parramatta - Main Distribution Board LCR Automatic Transfer Switches Design & Construction P2 (PARZ) (IMC154) (44108)</TD>
</TR>
<TR>
<TD class=label>Description:</TD>
<TD class=fieldlabel colspan=3>(NSW) Parramatta - Main Distribution Board LCR Automatic Transfer Switches Design & Construction P2 (PARZ) (IMC154) (44108)</TD>
</TR>
<TR>
<TD class=label>Issue No:</TD>
<TD class=fieldlabel>2</TD>
<TD class=label>Status:</TD>
<TD class=fieldLabel>
Project Approved</TD>
</TR>
</TABLE>
<!-- Divya : PBI000001666517 - 22Jun2017 release -->
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<BR>
<font color=blue>PCA Submit Request completed successfully.</font>
<P align=left>
<TABLE class="table" border=0 cellspacing=1 cellpadding=0 width="100%">
<TR>
<TD class="colHeader" colspan=5>Documents associated with the PCA </TD>
<TD class="cell" align="left" valign="center" colspan=3></TD>
</TR>
<TR>
<TD class="colHeader">Reference</TD>
<TD class="colHeader">Title</TD>
<TD class="colHeader">File Type</TD>
<TD class="colHeader">Issue No</TD>
<TD class="colHeader">Size(Bytes)</TD>
<TD class="colHeader">Date Registered</TD>
<TD class="colHeader">Registered By</TD>
<TD class="colHeader">View</TD>
</TR>
<TR class="cell">
<TD class="cell">CSS-1528090864510</TD>
<TD class="cell">PCA Documentation</TD>
<TD class="cell">DOCX</TD>
<TD class="cell">1</TD>
<TD class="cell">97904</TD>
<TD class="cell">04/06/2018</TD>
<TD class="cell">ADMIN USER</TD>
<TD valign="center" nowrap>
<A HREF="javascript:showDocument('40437320', 'CSS-1528090864510')"><P ALIGN=CENTER><IMG SRC='/global/res/images/attach.gif' width=16 height=16 ALT='97904 Bytes' BORDER=0><br>CSS-1528090864510.DOCX</P></A></TD>
</TR>
</TABLE>
答案 0 :(得分:0)
您可以使用以下方法找到您的元素:
//font[contains(text(),'PCA Submit Request completed successfully')]
在此元素出现之前,您可以像示例中那样设置暂停:
from selenium.webdriver.support import expected_conditions
element = WebDriverWait(driver, 10).until(
expected_conditions.presence_of_element_located((By.xPath, "xPath_to_element"))
)
或
browser.implicitly_wait(30)
答案 1 :(得分:0)
您可以尝试使用 xpath :
//font[text()='PCA Submit Request completed successfully.']
或
//font[contains(text(),'PCA Submit Request completed successfully.')]
正如您所提到的,某些条件必须满足您可以在 JAVA 和thread.sleep(time for waiting)
中明确等待或time.sleep(5)
strong> Python 这只是明确等待的最坏情况。