Ask a Question

clicking on web elements with no ID

darmstrong
Occasional Contributor

clicking on web elements with no ID

My AUT is a web app that has dynamically created pages.  Therefore, with the exception of the static widgets that are always present, there's no way to assign static IDs to the elements on the page.  I'm using the DOM tree model, and it's working great for those static widgets, but for dynamically created elements, I'm getting



Type    Message    Time    Link

There was an attempt to perform an action at point (59, 8), which is out of the window bounds.    14:36:14   



The line of the script being executed was recorded like this:



  all.Item(1038).Click(59, 8);



I'm wondering if the problem is that the DOM traversal isn't deterministic, and Item(1038) isn't always the same on subsequent loadings.  Is there a way for me to identify the element I want to select using xpath or this HTML?



<div class="hyperlink report-link list-panel-row">My Link Text</div>



Thanks,

Davina
4 REPLIES 4
AlexanderM
Staff

RE: clicking on web elements with no ID


Hello Davina,





As I mentioned in my reply in another thread, your assumption is correct - the IDs are not static, and it is not reliable to use them for object identification.





In your case, you can identify the element by its class and innerText properties:







function Test1()

{

  var p = Sys.Process("iexplore");

  var page = p.Page("*");





  var PropArray = new Array("className", "innerText");

  var ValuesArray = new Array("hyperlink report-link list-panel-row", "My Link Text");





  var ConvertedPropArray = ConvertJScriptArray(PropArray);

  var ConvertedValuesArray = ConvertJScriptArray(ValuesArray);

  

  var MyLink = page.Find(ConvertedPropArray, ConvertedValuesArray, 5);

  if (MyLink.Exists)

    Log.Message("Object found", MyLink.FullName);

  else

    Log.Error("The object is not found");

}





function ConvertJScriptArray(AArray)

{

  // Uses the Dictionary object to convert a JScript array

  var objDict = Sys.OleObject("Scripting.Dictionary");

  objDict.RemoveAll();

  for (var j in AArray)

    objDict.Add(j, AArray);

  return objDict.Items();

}







I hope this helps.
-----

Alexander
Customer Care Manager
darmstrong
Occasional Contributor

RE: clicking on web elements with no ID

This worked great!  Thanks!
darmstrong
Occasional Contributor

RE: clicking on web elements with no ID

I have another element without an ID that I can't figure out how to access.  I need to enter text in the textbox found in the following html:



<table cellspacing="4" cellpadding="0">

    <tbody>

        <tr>

            <td align="left" style="vertical-align: top;">

                <div class="gwt-Label">Name:</div>

            </td>

            <td align="left" style="vertical-align: top;">

                <input type="text" tabindex="0" class="gwt-TextBox">

            </td>

        </tr>

    </tbody>

</table>



Thanks,

Davina
AlexanderM
Staff

RE: clicking on web elements with no ID


Hi Davina,





What about searching for the text box by tagName="input" and className="gwt-TextBox"?
-----

Alexander
Customer Care Manager
cancel
Showing results for 
Search instead for 
Did you mean: