Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery ":contains()" analog for pure JS

I'm writing a script for CasperJS. I need to click on the link that contains a span with "1". In jQuery can be used :contains('1'), but what the solution is for selectors in pure Javascript?

HTML: <a class="swchItem"><span>1</span></a><a class="swchItem"><span>2</span></a>

jQuery variant: $('a .swchItem span:contains("1")')

UPD CasperJS code:

casper.then(function () {
    this.click('a .swchItem *select span with 1*')
})
like image 561
Ticksy Avatar asked Apr 13 '12 10:04

Ticksy


1 Answers

Since 0.6.8, CasperJS offers XPath support, so you can write something like this:

var x = require('casper').selectXPath;

casper.then(function() {
    this.click(x('//span[text()="1"]'))
})

Hope this helps.

like image 181
NiKo Avatar answered Oct 01 '22 00:10

NiKo