[英]How to check a specific value is displayed inside a table in Selenium Web driver
I am trying to validate a specific text inside a Table in a web page. 我正在尝试验证网页中表格中的特定文本。 the text is "ACTIVE". 文字是“有效”。 There are other places on the same page which displays the same text. 同一页面上还有其他位置显示相同的文本。 But I wanted to check "ACTIVE" within that table. 但我想检查该表中的“ACTIVE”。
I tried using driver.getPageSource().contains("ACTIVE"); 我尝试使用driver.getPageSource()。contains(“ACTIVE”); - However, this validates the entire page. - 但是,这会验证整个页面。
The Xpath of the element is : 元素的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 /table/tbody/tr[6]/td[2] 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]
And here the html below 这里是下面的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>
Try this XPATH expression: 试试这个XPATH表达式:
//tr[ *[ text() = 'Current Status' ] ]/td[ b ]
it finds TR element which contains a direct child with Current Status
text, and then it selects it's direct child TD ( a child of TR) which contains B tag. 它找到包含具有Current Status
文本的直接子节点的TR元素,然后选择它包含B标记的直接子TD(TR的子节点)。
or directy select second TD tag: 或者直接选择第二个TD标签:
//tr[ *[ text() = 'Current Status' ] ]/td[ 2 ]
You can also use this 你也可以用这个
//tr[ *[ text() = 'Current Status' ] ]/td[ text() = 'Active' ]
in order to check if Acive
text is present or visible on the screen in a field (row) named Current Status
. 为了检查Acive
文本是否在名为Current Status
的字段(行)中的屏幕上显示或可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.