4

Due to every ID being randomly generated after each refresh, I am having to use other identifiers. I basically want Robot to input text into a field next to my indicated identifier.

https://vgy.me/3YBIgl.png

I want text to be inputted to the user: field and using the "user:" as the locator to work with. It works with xpaths, but I would rather use another method which wont be so brittle.

Here is the HTML used to generate the form

<tbody id="m8DPe" class="z-rows">
<tr id="m8DPf" style="background:#FFFFFF;" class="z-row">
    <td id="m8DPg-chdextr" style="background:#FFFFFF;text-align:left;" class="z-row-inner">
        <div id="m8DPg-cell" class="z-row-content">
            <span id="m8DPg" class="z-label">User:</span>
        </div>
    </td>
    <td id="m8DPh-chdextr" style="background:#FFFFFF;text-align:left;" class="z-row-inner">
        <div id="m8DPh-cell" class="z-row-content">
            <input id="m8DPh" class="z-textbox" value="" type="text" name="j_username">
        </div>
    </td>
</tr>
<tr id="m8DPi" style="background:#FFFFFF;" class="z-row z-grid-odd">
    <td id="m8DPj-chdextr" style="background:#FFFFFF;text-align:left;" class="z-row-inner">
        <div id="m8DPj-cell" class="z-row-content">
        <span id="m8DPj" class="z-label">Password:</span>
        </div>
    </td>
    <td id="m8DPk-chdextr" style="background:#FFFFFF;text-align:left;" class="z-row-inner">
        <div id="m8DPk-cell" class="z-row-content">
            <input id="m8DPk" class="z-textbox" value="" type="password" name="j_password">
        </div>
    </td>
</tr>

I know it would be something similar to this:

Input Text    //tr[contains(text(), 'Example') and ...]    ${USERNAME}

But I honestly do not know. Is there somewhere I could read up on this?

I am extremely new to Robot Framework. Sorry for the noobness.

Goralight
  • 1,957
  • 4
  • 24
  • 33
  • 1
    Do you have the ability to work with the developers to change the HTML markup slightly? – Bryan Oakley Nov 18 '16 at 16:25
  • No I dont - We basically create it in Java, and then use the ZK API. They cant directly touch the HTML – Goralight Nov 18 '16 at 16:47
  • I had a similar problem in a project. I was able to use Python to calculate textbox xpaths based on their description xpaths. Because your ids look similar, you should be able to do it by stripping extra part of descriptor id. It sounds scary but I have found it makes readable and robust test automation. – Pekka Nov 21 '16 at 09:37
  • Pekka, I have no background in Python, and extremly new to all of this. Could you point me in the way to learn this? I am willing just dont know where to start – Goralight Nov 21 '16 at 09:39

1 Answers1

1

Looking at the sample, the name attribute for the input doesn'the look randomly generated. If that's really so, you could use the most trivial Selenium locator strategy by name, e.g.:

Input Text    name=j_username    ${USERNAME}

If that's not the case, this can be accomplished through an xpath:

//tr[//span[text()="User:"]/td//input

That reads (right-to-left for clearness, though it's evaluated LTR): return the input, which is inside a td (a cell), which itself is a direct child of a tr (a table row), having a span with that text (exact match here).

Thus, the locator will find the row having cell with "User:" in it, and will return the input in it.

Todor Minakov
  • 14,867
  • 2
  • 44
  • 49