Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xpath selectors to locate within elements. #3672

Merged
merged 2 commits into from
Apr 5, 2023
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/api/web-element/commands/findAllByText.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {By} = require('selenium-webdriver');

module.exports.command = function (text, {exact = true} = {}) {
const expr = exact ? `text()="${text}"` : `contains(text(),"${text}")`;
const selector = By.xpath(`//*[${expr}]`);
const selector = By.xpath(`.//*[${expr}]`);

return this.createScopedElements({selector}, {parentElement: this, commandName: 'findAllByText'});
};
10 changes: 5 additions & 5 deletions lib/api/web-element/commands/findByLabelText.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {By} = require('selenium-webdriver');
module.exports.command = function (text, {exact = true, ...options} = {}) {
const findByForId = async (text, {exact, ...options}) => {
const expr = exact ? `text()="${text}"` : `contains(text(),"${text}")`;
const selector = By.xpath(`//label[${expr}]`);
const selector = By.xpath(`.//label[${expr}]`);

const labelWebElement = await this.find({
...options,
Expand All @@ -30,7 +30,7 @@ module.exports.command = function (text, {exact = true, ...options} = {}) {

const findByAriaLabelled = async (text, {exact, ...options}) => {
const expr = exact ? `text()="${text}"` : `contains(text(),"${text}")`;
const selector = By.xpath(`//label[${expr}]`);
const selector = By.xpath(`.//label[${expr}]`);

const labelWebElement = await this.find({
...options,
Expand All @@ -57,7 +57,7 @@ module.exports.command = function (text, {exact = true, ...options} = {}) {

const findByDirectNesting = async (text, {exact, ...options}) => {
const expr = exact ? `text()="${text}"` : `contains(text(),"${text}")`;
const selector = By.xpath(`//label[${expr}]`);
const selector = By.xpath(`.//label[${expr}]`);

const labelElementPromise = this.find({
...options,
Expand All @@ -80,8 +80,8 @@ module.exports.command = function (text, {exact = true, ...options} = {}) {

const findByDeepNesting = async (text, {exact, ...options}) => {
const selector = exact
? By.xpath(`//label[*[text() = "${text}"]]`)
: By.xpath(`//label[*[contains(text(), "${text}")]]`);
? By.xpath(`.//label[*[text() = "${text}"]]`)
: By.xpath(`.//label[*[contains(text(), "${text}")]]`);

const labelElementPromise = this.find({
...options,
Expand Down
4 changes: 2 additions & 2 deletions lib/api/web-element/commands/findByText.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const {By} = require('selenium-webdriver');

module.exports.command = function(text, {exact = true, ...options} = {}) {
const selector = exact
? By.xpath(`//*[text()="${text}"]`)
: By.xpath(`//*[contains(text(),"${text}")]`);
? By.xpath(`.//*[text()="${text}"]`)
: By.xpath(`.//*[contains(text(),"${text}")]`);

return this.find({
...options,
Expand Down
6 changes: 3 additions & 3 deletions test/src/api/commands/web-element/testFindAllByText.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('element().findAllByText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//*[text()="Email"]'
value: './/*[text()="Email"]'
},
method: 'POST',
response: JSON.stringify({
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('element().findAllByText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//*[contains(text(),"Email")]'
value: './/*[contains(text(),"Email")]'
},
method: 'POST',
response: JSON.stringify({
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('element().findAllByText() commands', function () {
url: '/session/13521-10219-202/elements',
postdata: {
using: 'xpath',
value: '//*[text()="Email"]'
value: './/*[text()="Email"]'
},
method: 'POST',
response: JSON.stringify({
Expand Down
17 changes: 8 additions & 9 deletions test/src/api/commands/web-element/testFindByLabelText.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const CommandGlobals = require('../../../../lib/globals/commands-w3c.js');
const Element = require('../../../../../lib/element/index.js');

describe('.findByLabelText() commands', function () {
this.timeout(10000000);
before(function (done) {
CommandGlobals.beforeEach.call(this, done);
});
Expand All @@ -20,7 +19,7 @@ describe('.findByLabelText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//label[text()="Email"]'
value: './/label[text()="Email"]'
},
method: 'POST',
response: JSON.stringify({
Expand Down Expand Up @@ -65,7 +64,7 @@ describe('.findByLabelText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//label[contains(text(),"Email")]'
value: './/label[contains(text(),"Email")]'
},
method: 'POST',
response: JSON.stringify({
Expand Down Expand Up @@ -111,7 +110,7 @@ describe('.findByLabelText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//label[text()="Email"]'
value: './/label[text()="Email"]'
},
method: 'POST',
response: JSON.stringify({
Expand Down Expand Up @@ -163,7 +162,7 @@ describe('.findByLabelText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//label[text()="Email"]'
value: './/label[text()="Email"]'
},
method: 'POST',
response: JSON.stringify({
Expand Down Expand Up @@ -209,7 +208,7 @@ describe('.findByLabelText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//label[text()="Email"]'
value: './/label[text()="Email"]'
},
method: 'POST',
response: JSON.stringify({
Expand All @@ -221,7 +220,7 @@ describe('.findByLabelText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//label[*[text() = "Email"]]'
value: './/label[*[text() = "Email"]]'
},
method: 'POST',
response: JSON.stringify({
Expand Down Expand Up @@ -259,7 +258,7 @@ describe('.findByLabelText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//label[text()="Email"]'
value: './/label[text()="Email"]'
},
method: 'POST',
response: JSON.stringify({
Expand All @@ -271,7 +270,7 @@ describe('.findByLabelText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//label[*[text() = "Email"]]'
value: './/label[*[text() = "Email"]]'
},
method: 'POST',
response: JSON.stringify({
Expand Down
4 changes: 2 additions & 2 deletions test/src/api/commands/web-element/testFindByText.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('.findByText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//*[text()="Submit"]'
value: './/*[text()="Submit"]'
},
method: 'POST',
response: JSON.stringify({
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('.findByText() commands', function () {
url: '/session/13521-10219-202/element/0/elements',
postdata: {
using: 'xpath',
value: '//*[contains(text(),"Submit")]'
value: './/*[contains(text(),"Submit")]'
},
method: 'POST',
response: JSON.stringify({
Expand Down