Quality Testing

Quality is delighting customers

Hi ,

Given below is the HTML code

I am trying to fetch the text from "//table[x]/tbody/tr/td[2]/a"

I am getting the text for

table[1] = Administration

table[2] = Engg (Process & Proj Mgmt)

But getting blank for table[3] instead of Finance.

What went wrong ?????


<div id="MTn0Nodes" style="display: none;">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody>
<tr>
   <td>
      <td class="LfSbLnk MT_2 L1 MT_10 LfBg LRoot MT_4" style="white-space:nowrap;">
            <a id="MTt9" class="MT_0 LfSbLnk MT_1 L1 MT_9 LfBg LRoot MT_3" >Administration</a>
    </td>
</tr>
</tbody>
</table>
 

<div id="MTn9Nodes" style="display:none;">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody>
   <tr>
      <td>
       <td class="LfSbLnk MT_2 L1 MT_10 LfBg LRoot MT_4 style="white-space:nowrap;">

          <a id="MTt25" class="MT_0 LfSbLnk MT_1 L1 MT_9 LfBg LRoot MT_3">Engg (Process & Proj Mgmt)</a>
      </td>
  </tr>
</tbody>
</table>


<div id="MTn25Nodes" style="display:none;">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody>
  <tr>
    <td>
    <td class="LfSbLnk MT_2 L1 MT_10 LfBg LRoot MT_4" style="white-space:nowrap;">
        <a id="MTt38" class="MT_0 LfSbLnk MT_1 L1 MT_9 LfBg LRoot MT_3">Finance</a>
    </td>
   </tr>
</tbody>
</table>

Views: 364

Reply to This

Replies to This Discussion

try this "//table[x]/tbody/tr/td[3]/a"

sry if am wrng

this will be wrong xpath niru...

use fire path add on to find xpath...then it ll work.

Hi Sara:

Maybe this URL will help you to try your xpath 

http://www.xpathtester.com/

First of all validate that your XML code has the correct format ! xD

Regards

Still I am struglling with the same issue...

If I write :

driver.getPageSource().contains("Finance"))

It returns TRUE.

But when I give Xpath ans try ti getText it gives me empty string...

driver.findElement(By.xpath("//table[4]/tbody/tr/td[2]/a")).getText())...

Why it is working like this???????

instead of .getText use .getAttribute("values");

try with this 

//div[starts-with(@id,'MT')]/table[x]/tbody/tr/td[3]/a/  

if the above not work then try with the following

//div[starts-with(@id,'MT')]/table[3]/tbody/tr/td[3]/a/

Still it gives empty string for "Finance"

If I use :

driver.findElement(By.id("MTt38")).getText()

It gives expected result as "Finance"..

but if u use id =MTt38 then it will be static approach i.e if  id gets change then it will return error.

as per Your provided description you are not able to access the third element which is in this case Finance, but if in future Accountancy comes in third position instead of finance then it will return error as the id will get change.

so we have to write the Xpath in certain way so that we can access member of that position irresptive of their id.

as per the html u have given div have started but there is no end tag for div , is this html is correct?

can u try with this xpath 

//div[3]/table/tbody/tr/td[2]/a/

or 

//div[3]/table/tbody/tr/td[2]/a[starts-with(@id,'MT')]/

i am assuming that  id will always start with MT

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2019   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service