- var terms = $("div.mkwsFacet[data-mkws-facet='xtargets'] div.term a");
- for (var i = 0; i < terms.length; i++) {
- var term = $(terms[i]).text();
- if (term.match(/wikipedia/i)) {
- debug("ignore source facet: " + term);
- source_number++;
- } else {
- break;
+ var link = "div.mkwsFacet[data-mkws-facet='xtargets'] div.term a";
+
+ // wait for a visible source link in facets
+ waitsFor(function () {
+ var terms = $(link);
+ return terms && terms.length > 0;
+ }, "wait for source facets after author search", 5 * jasmine_config.second);
+
+
+ runs(function () {
+ var terms = $(link);
+ for (var i = 0; i < terms.length; i++) {
+ var term = $(terms[i]).text();
+ debug("check for good source: " + term);
+
+ if (term.match(/wikipedia/i)) {
+ debug("ignore source facet: " + term);
+ source_number++;
+ } else {
+ break;
+ }
+ }
+ debug("Source counter: " + terms.length + ", select: " + (source_number - 1));
+
+ if ($("div.mkwsFacet[data-mkws-facet='xtargets'] div.term:nth-child(" + source_number + ") a").text().length == 0) {
+ debug("No good source found. Not clicking on the bad ones");
+ return;