diff --git a/lib/api/web-element/commands/findAllByText.js b/lib/api/web-element/commands/findAllByText.js index 2193f7b7f8..bace17c813 100644 --- a/lib/api/web-element/commands/findAllByText.js +++ b/lib/api/web-element/commands/findAllByText.js @@ -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'}); }; diff --git a/lib/api/web-element/commands/findByLabelText.js b/lib/api/web-element/commands/findByLabelText.js index c57389a9c2..ff6e561326 100644 --- a/lib/api/web-element/commands/findByLabelText.js +++ b/lib/api/web-element/commands/findByLabelText.js @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/lib/api/web-element/commands/findByText.js b/lib/api/web-element/commands/findByText.js index d0051f25f9..39587aa120 100644 --- a/lib/api/web-element/commands/findByText.js +++ b/lib/api/web-element/commands/findByText.js @@ -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, diff --git a/test/src/api/commands/web-element/testFindAllByText.js b/test/src/api/commands/web-element/testFindAllByText.js index 1d9fdce3f6..ba8eb37615 100644 --- a/test/src/api/commands/web-element/testFindAllByText.js +++ b/test/src/api/commands/web-element/testFindAllByText.js @@ -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({ @@ -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({ @@ -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({ diff --git a/test/src/api/commands/web-element/testFindByLabelText.js b/test/src/api/commands/web-element/testFindByLabelText.js index 1907697b4e..c583e0db90 100644 --- a/test/src/api/commands/web-element/testFindByLabelText.js +++ b/test/src/api/commands/web-element/testFindByLabelText.js @@ -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); }); @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ diff --git a/test/src/api/commands/web-element/testFindByText.js b/test/src/api/commands/web-element/testFindByText.js index 3ce32d7a02..af52bd8950 100644 --- a/test/src/api/commands/web-element/testFindByText.js +++ b/test/src/api/commands/web-element/testFindByText.js @@ -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({ @@ -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({