Skip to content

Commit

Permalink
Fix handling of attribute when hiding keyboard (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
imurchie committed Jul 31, 2019
1 parent 8b44fcc commit a5d996b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/commands/element.js
Expand Up @@ -18,6 +18,8 @@ commands.getNativeAttribute = async function getNativeAttribute (attribute, el)
return await this.getContentSize(el);
}

el = util.unwrapElement(el);

// otherwise let WDA handle attribute requests
let value = await this.proxyCommand(`/element/${el}/attribute/${attribute}`, 'GET');
// Transform the result for the case when WDA returns an integer representation for a boolean value
Expand Down
12 changes: 8 additions & 4 deletions lib/commands/general.js
Expand Up @@ -114,11 +114,11 @@ commands.hideKeyboard = async function hideKeyboard (strategy, ...possibleKeys)
try {
await this.proxyCommand('/wda/keyboard/dismiss', 'POST');
return;
} catch (err) {
log.debug('Cannot dismiss the keyboard using the native call. Trying to apply a workaround...');
}
} catch (ign) {}
}

log.debug('Cannot dismiss the keyboard using the native call. Trying to apply a workaround...');

let keyboard;
try {
keyboard = await this.findNativeElementOrElements('class name', 'XCUIElementTypeKeyboard', false);
Expand All @@ -130,7 +130,7 @@ commands.hideKeyboard = async function hideKeyboard (strategy, ...possibleKeys)
possibleKeys.pop(); // last parameter is the session id
possibleKeys = possibleKeys.filter((element) => !!element); // get rid of undefined elements
if (possibleKeys.length) {
for (let key of possibleKeys) {
for (const key of possibleKeys) {
let el = _.last(await this.findNativeElementOrElements('accessibility id', key, true, keyboard));
if (el) {
log.debug(`Attempting to hide keyboard by pressing '${key}' key.`);
Expand All @@ -146,6 +146,10 @@ commands.hideKeyboard = async function hideKeyboard (strategy, ...possibleKeys)
return;
}
let buttons = await this.findNativeElementOrElements('class name', 'XCUIElementTypeButton', true, keyboard);
if (_.isEmpty(buttons)) {
log.warn(`No button elements found. Unable to hide.`);
return;
}
await this.nativeClick(_.last(buttons));
}
};
Expand Down

0 comments on commit a5d996b

Please sign in to comment.