Skip to content

Commit 0d2ef39

Browse files
authored
fix: cannot locate complicated locator (#4101)
1 parent 1a9f3be commit 0d2ef39

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lib/locator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const cssToXPath = require('convert-cssxpath');
1+
const cssToXPath = require('csstoxpath');
22
const { sprintf } = require('sprintf-js');
33

44
const { xpathLocator } = require('./utils');
@@ -162,7 +162,7 @@ class Locator {
162162
*/
163163
toXPath() {
164164
if (this.isXPath()) return this.value;
165-
if (this.isCSS()) return cssToXPath.convert(this.value);
165+
if (this.isCSS()) return cssToXPath(this.value);
166166

167167
throw new Error('Can\'t be converted to XPath');
168168
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
"chai-string": "^1.5.0",
8282
"chalk": "4.1.2",
8383
"commander": "11.1.0",
84-
"convert-cssxpath": "1.0.2",
8584
"cross-spawn": "7.0.3",
85+
"csstoxpath": "1.6.0",
8686
"envinfo": "7.11.0",
8787
"escape-string-regexp": "4.0.0",
8888
"figures": "3.2.0",
@@ -121,6 +121,7 @@
121121
"@wdio/sauce-service": "8.27.0",
122122
"@wdio/selenium-standalone-service": "8.3.2",
123123
"@wdio/utils": "8.27.0",
124+
"@xmldom/xmldom": "0.8.10",
124125
"apollo-server-express": "2.25.3",
125126
"chai-as-promised": "7.1.1",
126127
"chai-subset": "1.6.0",
@@ -157,7 +158,6 @@
157158
"wdio-docker-service": "1.5.0",
158159
"webdriverio": "8.3.8",
159160
"xml2js": "0.6.2",
160-
"@xmldom/xmldom": "0.8.10",
161161
"xpath": "0.0.34"
162162
},
163163
"engines": {

test/unit/locator_test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ const xml = `<body>
5252
<label class="n-1">Hello<a href="#">Please click</a></label>
5353
</div>
5454
<input type="hidden" name="return_url" value="" id="return_url" />
55+
56+
<div class="ps-submenu-root">
57+
<ul class="ps-submenu-root">
58+
<li class="ps-menu-button">Adhemar da Silva</li>
59+
<li class="ps-menu-button">HelloWorld</li>
60+
<li class="ps-menu-button">Hallo</li>
61+
</ul>
62+
<ul class="ps-submenu-root">
63+
<li class="ps-menu-button">Adhemar da Silva</li>
64+
<li class="ps-menu-button">HelloWorld</li>
65+
<li class="ps-menu-button">Authoring</li>
66+
</ul>
67+
</div>
5568
</body>`;
5669

5770
describe('Locator', () => {
@@ -272,4 +285,14 @@ describe('Locator', () => {
272285
expect(nodes[0].firstChild.data).to.eql('Sign In', l.toXPath());
273286
Locator.filters = [];
274287
});
288+
289+
it('should be able to locate complicated locator', () => {
290+
const l = Locator.build('.ps-menu-button')
291+
.withText('Authoring')
292+
.inside('.ps-submenu-root:nth-child(2)');
293+
294+
const nodes = xpath.select(l.toXPath(), doc);
295+
expect(nodes).to.have.length(1, l.toXPath());
296+
expect(nodes[0].firstChild.data).to.eql('Authoring', l.toXPath());
297+
});
275298
});

0 commit comments

Comments
 (0)