Skip to content

Commit 0de9018

Browse files
committed
fix: tap on first element in click command
1 parent bf89d48 commit 0de9018

File tree

2 files changed

+7
-3
lines changed
  • lib/command-helpers/element-utils
  • test/lib/command-helpers/element-utils

2 files changed

+7
-3
lines changed

lib/command-helpers/element-utils/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ exports.getWebViewSize = async (browser) => {
3232
exports.getElemCoords = async (browser, selector) => {
3333
const [size, location] = await Promise.all([browser.getElementSize(selector), browser.getLocation(selector)]);
3434
const {width, height} = _.isArray(size) ? size[0] : size;
35-
const {x, y} = _.isArray(location) ? location[0] : location;
35+
// wdio returns elements in reverse order, so we need to take the last element in the array to pick first element on the page
36+
// https://github.com/webdriverio/webdriverio/blob/v4.14.1/lib/commands/getLocation.js#L48.
37+
const {x, y} = _.isArray(location) ? location[location.length - 1] : location;
3638

3739
const topToolbarHeight = await exports.getTopToolbarHeight(browser);
3840

test/lib/command-helpers/element-utils/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ describe('"element-utils" helper', () => {
132132
assert.deepEqual(coords, {width: 10, height: 20, x: 1, y: 2});
133133
});
134134

135-
it('should return coords of first found element', async () => {
135+
// wdio returns elements in reverse order, so we need to take last element in array to pick first element on the page
136+
// https://github.com/webdriverio/webdriverio/blob/v4.14.1/lib/commands/getLocation.js#L48.
137+
it('should return coords of last found element', async () => {
136138
browser.getElementSize.withArgs('some-selector').returns(
137139
[{width: 10, height: 20}, {width: 100, height: 200}]
138140
);
@@ -142,7 +144,7 @@ describe('"element-utils" helper', () => {
142144

143145
const coords = await utils.getElemCoords(browser, 'some-selector');
144146

145-
assert.deepEqual(coords, {width: 10, height: 20, x: 1, y: 2});
147+
assert.deepEqual(coords, {width: 10, height: 20, x: 11, y: 22});
146148
});
147149

148150
it('should increase y coordinate on top toolbar height', async () => {

0 commit comments

Comments
 (0)