UFT One cannot use xpath following-sibling

I need to create scripting to click the button next to one object. Due to the customer requested not to use Repo, I tried DP but the objects didn't have unique properties so I used the xpath.

the structure is like below:
<td> Row 1</td>
<td>
<input class=button></input>
</td>

The issue is I cannot use "following sibling" in UFT (I tested it in the browser and works but failed in UFT)
xpath 1: //td[title()='Row 1']/following-sibling::td//input[@class='button'] -> FAILED
xpath 2: (//td[title()='Row 1']/..//td//input[@class='button'])[1]-> SUCCESS

the xpath 2 is the workaround but tbh should be avoided because of the index. Could anyone suggest the cause UFT cannot use the sibling and give a good alternative for the xpath?

This case also applies to other siblings like "preceding-sibling" and "ancestor".

Tags:

Parents
  • 0  

    Hi,

    The "following sibling" or other siblings are supported in UFT One.

    I have tried the following code to verify the xpath.

    • HTML

    <!DOCTYPE html>
    <html>
        <head>
            <title>Page title</title>
        </head>
        <body>
            <table>
                <td>Row 1</td>
                <td>
                    <input class="button"></input>
                </td>
            </table>
    
        </body>
    </html>

    • UFT script

    Browser("creationtime:=0").Page("micclass:=page").WebElement("xpath:=//td[text()='Row 1']/following-sibling::td//input[@class='button']").Highlight

    The `input object` can be highlighted successfully.

    Please run $x("your xpath description") in the browser console to check if it can find the right object.

Reply
  • 0  

    Hi,

    The "following sibling" or other siblings are supported in UFT One.

    I have tried the following code to verify the xpath.

    • HTML

    <!DOCTYPE html>
    <html>
        <head>
            <title>Page title</title>
        </head>
        <body>
            <table>
                <td>Row 1</td>
                <td>
                    <input class="button"></input>
                </td>
            </table>
    
        </body>
    </html>

    • UFT script

    Browser("creationtime:=0").Page("micclass:=page").WebElement("xpath:=//td[text()='Row 1']/following-sibling::td//input[@class='button']").Highlight

    The `input object` can be highlighted successfully.

    Please run $x("your xpath description") in the browser console to check if it can find the right object.

Children
  • 0 in reply to   

    hello, I run the xpath in the browser console before executing it in UFT.

    for the example:  //td[title()='Row 1']/following-sibling::td//input[@class='button'] 

    the xpath find the object in the browser console but it failed in UFT.

    For the same object in UFT, I have to use this xpath

    (//td[title()='Row 1']/..//td//input[@class='button'])[1]