This is a migrated thread and some comments may be shown as answers.

Problem with identifying dynamically generated elements using Mobile Testing

1 Answer 30 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
hasantha
Top achievements
Rank 1
hasantha asked on 22 Jun 2014, 04:41 AM
Telerik Mobile Testing uses name-value pair properties that specify one or more attributes of the target element that we want to operate. So what about dynamically(on the fly) generated elements? How can we identify a dynamically(on the fly) generated element without knowing the values of attributes of that element? 

We have an hybrid android application and  in a certain UI in the application, we have a html table which populates itself dynamically  with values from a data base. Each retrieved value is placed inside a dynamically generated <td> element  inside the <table> element and note that these dynamically generated <td> elements do not have unique ids.  So how can we identify these <td> elements uniquely?  

1 Answer, 1 is accepted

Sort by
0
Shtilianov
Telerik team
answered on 23 Jun 2014, 12:03 PM
Hello,

Unfortunately, there is no simple way to get dynamicaly generated element by their value. There are a number of other ways to do that tough.

The simplest way is to get the <td> elements by searching them by tag and index, for example:

// finds all td elements, then selects the element at index 0 (the 1st `td` tablecell)

{tagName:
'td', index: 0}


Another way is to get all of the elements in the table and loop through them and filtering them by value:

// put all table cells in an array
var tds = document.getElementsByTagName('td);

for (i = 0; i < tds.lenght; i++) {
if (tds[i].value == "desiredValue")
{
// return the tablecell
return tds[i];
}
}

To make this script execute on the web app under test you have to put it in executeScript like this (Note: you have to put the whole script from above into a single string, check this article)

var scriptAsString = "for (i = 0; i < tds.lenght; i++) { if (tds[i]......";

web.executeScript(scriptAsString, function(r) {
    // r is the tablecell that we get from from the script
    console.log(r);
    web.click(r);
    });


Regards,
Shtilianov
Telerik 
Test your Android and iOS apps against any device or browser with Telerik Mobile Testing. Part of the Telerik Platform.
 
Tags
General Discussions
Asked by
hasantha
Top achievements
Rank 1
Answers by
Shtilianov
Telerik team
Share this question
or