Skip to content

Commit 14e465c

Browse files
authored
fixed 4447 (#4448)
1 parent 4acfce3 commit 14e465c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/locator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class Locator {
175175
*/
176176
toXPath(pseudoSelector = '') {
177177
const locator = `${this.value}${pseudoSelector}`;
178-
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'];
178+
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'];
179179

180180
if (limitation.some(item => locator.includes(item))) {
181181
cssToXPath = require('css-to-xpath');

test/unit/locator_test.js

+9
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@ describe('Locator', () => {
300300
expect(nodes[0].firstChild.data).to.eql('davert')
301301
})
302302

303+
it('should transform CSS having has pseudo to xpath', () => {
304+
const l = new Locator('#submit-element:has(button)', 'css')
305+
const convertedXpath = l.toXPath();
306+
const nodes = xpath.select(l.toXPath(), doc)
307+
expect(convertedXpath).to.equal('.//*[(./@id = \'submit-element\' and .//button)]')
308+
expect(nodes).to.have.length(1)
309+
expect(nodes[0].firstChild.data.trim()).to.eql('')
310+
})
311+
303312
it('should build locator to match element by attr', () => {
304313
const l = Locator.build('input').withAttr({ 'data-value': 'yes' })
305314
const nodes = xpath.select(l.toXPath(), doc)

0 commit comments

Comments
 (0)