FotisK
FotisK

Reputation: 1177

How to select specific element based on a part of its attribute with CasperJS

This issue seems very easy and I have found some threads about it but those solutions don't work when we have multiple tabs more the 2 tabs to select from.

Example: enter image description here

So in this case when I use (goal is to select the tab "Routing"):

...    
    casper.then(function() {
        test.assertTextExists("Test", "Test - tab");
        this.click('a.menu1itemUnSel[tabindex="4"]');
    });
...

It will select the first not selected tab "Data" and not tab "Routing"!

How can I solve this issue?

Upvotes: 0

Views: 58

Answers (1)

Artjom B.
Artjom B.

Reputation: 61892

Again, CSS selectors are your friend for example with a specific attribute selector matching the content of the attribute:

this.click('a.menu1itemUnSel[href*="tabIndex.value=\'3\'"]');

or

var i = 3;
this.click('a.menu1itemUnSel[href*="tabIndex.value=\''+i+'\'"]');

Upvotes: 2

Related Questions