简体   繁体   English

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

[英]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.

相关问题 如何通过使用Java为Selenium Web驱动程序中的复选框编写脚本 - How to write the script for the check box in Selenium web driver by using Java 如何使用Java中的Selenium Web驱动程序检查元素形成的csv文件? - how to check elements form a csv file with selenium web driver in java? Selenium Web驱动程序-如何检查页面中是否所有产品都已加载 - Selenium Web Driver - How to check whether all the products in a page loads 如何从Selenium Web Driver JAVA中的表中获取元素 - How to get elements from table in Selenium Web Driver JAVA 如何使用Java在Selenium Web Driver中使用分页来搜索表中的元素 - How to search an element in a table using pagination in selenium Web Driver with java 如何在Selenium Web驱动程序中获取跨度类值的属性 - how to getattribute of a span class value in selenium web driver 如何使用Selenium Web驱动程序在代码镜像中输入值? - How to input value in code mirror using selenium web driver? 如何使用Java(Selenium Web Driver)从下拉列表中选择值 - How to select value from dropdown using java (selenium web driver) 如何使用Java逐一检查Selenium Web驱动程序中的所有复选框? - How to check all check-boxes one by one in selenium web driver with the java? 如何在另一个html标签中选择带有html源的Web元素硒Web驱动程序 - How can select web element selenium web driver with html source inside another html tag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM