代码之家  ›  专栏  ›  技术社区  ›  johnsonambrose

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

  •  1
  • johnsonambrose  · 技术社区  · 8 年前

    Active

    我试图验证网页中表内的特定文本。文本为“活动”。同一页上还有其他地方显示相同的文本。但我想检查表中的“ACTIVE”。

    我试着使用驱动程序。getPageSource()。包含(“活动”);-但是,这会验证整个页面。

    元素的Xpath是:

    1 /td/表格 1. /tbody/tr/td/table[4]/tbody/tr/td 1. /表/t正文/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>
    
    1 回复  |  直到 8 年前
        1
  •  4
  •   krokodilko    8 年前

    尝试以下XPATH表达式:

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

    它查找TR元素,该元素包含一个具有 Current Status 文本,然后选择它的直接子TD(TR的子项),其中包含B标记。

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

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

    你也可以用这个

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

    Acive 文本在屏幕上名为的字段(行)中显示或可见 当前状态 .