繁体   English   中英

如何检查特定值显示在Selenium Web驱动程序的表中

[英]How to check a specific value is displayed inside a table in Selenium Web driver

活性

我正在尝试验证网页中表格中的特定文本。 文字是“有效”。 同一页面上还有其他位置显示相同的文本。 但我想检查该表中的“ACTIVE”。

我尝试使用driver.getPageSource()。contains(“ACTIVE”); - 但是,这会验证整个页面。

元素的Xpath是:

html / body / table / tbody / tr / td [2] / form / table [2] / tbody / tr 1 / td / table 1 / tbody / tr / td / table [4] / tbody / tr / td 1 /表/ TBODY / TR [6] / TD [2]

这里是下面的html

<html>
<head>
<body leftmargin="2" topmargin="2" onload="initializeData()" marginwidth="2" marginheight="2" bgcolor="#ffffff">
<table width="756">
<tbody>
<tr>
<td width="9"/>
<td width="764">
<form frm_id="frm" name="frm">
<table width="754" cellspacing="0" cellpadding="0" border="0">

<table height="629" width="763">
<tbody>
<tr>
<td height="625" width="770">
<table width="728">
<tbody>
<tr>
<td>
<table height="10" width="739" cellspacing="0" cellpadding="0" border="0">
<table height="10" width="736" cellspacing="0" cellpadding="0" border="0">
<table height="4" width="740" cellspacing="0" cellpadding="0" border="0">
<table height="86" width="100%" border="1">
<tbody>
<tr>
<td height="80" width="33%" valign="top">
<table height="267" width="103%" border="0">
<tbody>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<td height="20" width="47%" align="left">Current Status</td>
<td height="20" width="155%">
<b>:</b>
 ACTIVE 
</td>

试试这个XPATH表达式:

//tr[ *[ text() = 'Current Status' ] ]/td[ b ]

它找到包含具有Current Status文本的直接子节点的TR元素,然后选择它包含B标记的直接子TD(TR的子节点)。

或者直接选择第二个TD标签:

//tr[ *[ text() = 'Current Status' ] ]/td[ 2 ]

你也可以用这个

//tr[ *[ text() = 'Current Status' ] ]/td[ text() = 'Active' ]

为了检查Acive文本是否在名为Current Status的字段(行)中的屏幕上显示或可见。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM