vendredi 11 septembre 2015

assertExists with if-else statement

I use this code:

var x = require('casper').selectXPath;
...
casper.waitForSelector(x("//a[contains(@id,'cell_13_1')]"), function() {             
    this.test.assertExists(x("//a[contains(@id,'cell_13_1')]"), 'Clickable');
    this.click(x("//a[contains(@id,'cell_13_1')]"));
});

I am trying to use if-else with assertExists to click another element if the first is not there:

casper.waitForSelector(x("//a[contains(@id,'cell_13_1')]"), function() {          
    if(this.test.assertExists(x("//a[contains(@id,'cell_13_1')]")==="PASS"){
        this.click(x("//a[contains(@id,'cell_11_1')]"));} 
    else{
        this.click(x("//a[contains(@id,'cell_22_1')]"));
    }         
});

But that does not seem to work. How would one do it correctly?

Aucun commentaire:

Enregistrer un commentaire