From 70a213fd0a9c80baaad29bc6ad00a995e5b887e8 Mon Sep 17 00:00:00 2001 From: anils92 Date: Mon, 29 Jul 2024 18:35:34 +0200 Subject: [PATCH] fixed 4447 --- lib/locator.js | 2 +- test/unit/locator_test.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/locator.js b/lib/locator.js index 1c958b9d9..f10a94399 100644 --- a/lib/locator.js +++ b/lib/locator.js @@ -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'); diff --git a/test/unit/locator_test.js b/test/unit/locator_test.js index a638d1dc4..aec941a8b 100644 --- a/test/unit/locator_test.js +++ b/test/unit/locator_test.js @@ -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)