Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/locator.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class Locator {
*/
toXPath(pseudoSelector = '') {
const locator = `${this.value}${pseudoSelector}`;
const limitation = [':nth-of-type', ':first-of-type', ':last-of-type', ':nth-last-child', ':nth-last-of-type', ':checked', ':disabled', ':enabled', ':required', ':lang', ':nth-child'];
const limitation = [':nth-of-type', ':first-of-type', ':last-of-type', ':nth-last-child', ':nth-last-of-type', ':checked', ':disabled', ':enabled', ':required', ':lang', ':nth-child', ':has'];

if (limitation.some(item => locator.includes(item))) {
cssToXPath = require('css-to-xpath');
Expand Down
9 changes: 9 additions & 0 deletions test/unit/locator_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ describe('Locator', () => {
expect(nodes[0].firstChild.data).to.eql('davert')
})

it('should transform CSS having has pseudo to xpath', () => {
const l = new Locator('#submit-element:has(button)', 'css')
const convertedXpath = l.toXPath();
const nodes = xpath.select(l.toXPath(), doc)
expect(convertedXpath).to.equal('.//*[(./@id = \'submit-element\' and .//button)]')
expect(nodes).to.have.length(1)
expect(nodes[0].firstChild.data.trim()).to.eql('')
})

it('should build locator to match element by attr', () => {
const l = Locator.build('input').withAttr({ 'data-value': 'yes' })
const nodes = xpath.select(l.toXPath(), doc)
Expand Down