Tuesday 5 May 2015

How Can I Use JavaScript to Locate Objects in Ajax True client script?

Using the JavaScript identification method you can write JavaScript code that references the returned
document and can use CSS selectors and other standard functions.

For example, the page returned by the server contains multiple links with the same “title” attribute
(search results) and we want the script to randomly click on one of the available links.
Object identification for this case, using the JavaScript identification method, may look something like this:

var my_results = document.querySelectorAll('a[title="SearchResult"]');
my_results[Math.floor(Math.random() * my_results.length)];

No comments: