0
votes

Here is a snapshot of my page under test:

<div class="menubox1">
  <table class="menubox1box1">
    <tbody>
      <tr class="menubox2">
        <td class="menubox22">
          <table class="menubox221">
            <tbody>
              <tr>
                <td class="menubox2211" id="tdMenuBar">
                  <table id="tblMenuBar">
                    <tbody>
                      <tr id="mytr">
                      <>
                      <div id="divMenu">

I have to access the div using xpath but there is an empty node just above it. How should I handle such empty nodes?

I tried framing this: By.xpath("//*[@class=\"menubox1\"]/table/tbody/tr/td/table/tbody//div")

It failed to identify the element. Am I missing something here?

3
does XML allow empty nodes? - Javier
I am not sure why it is needed but it seems possible. The above is from a page of IBM's sterling application. - Janaaaa

3 Answers

0
votes

Your current XPATH is wrong. There's a solution :

By.xpath("//div[@class='menubox1']/table/tbody/tr/td/table/tbody/tr/td/table/tbody/div")

Try this easy way below and tell me what's up.

By.xpath("//div[@id='divMenu']")

PS :

Can you explain more about your empty node.

It's like :

<table id="tblMenuBar">
  <tbody>
    <tr id="mytr">
    <>
    <div id="divMenu">
</table>

or

<table id="tblMenuBar">
  <tbody>
    <tr id="mytr">
    <>
      <div id="divMenu">
    <>
</table>
0
votes

Give a try with below locators.

By.cssSelector("#tblMenuBar #divMenu")

or

By.cssSelector("#tdMenuBar > #tblMenuBar #divMenu")

P.S. : If something has dynamic locator or not unique, try to locate that element with respect to some unique locator.

0
votes

The solution by e1che should work and in case you are interested in particular div like //div[@class='menubox1'] you can try this. This would select the children div's of the div with particular class attribute(menubox1) whose id match divMenu.

By.xpath(//div[@class='menubox1']/descendant::div[@id='divMenu'])