Skip to content

OI-1067 focus trick #127

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions src/ox_modules/module-web/commands/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ module.exports = async function(locator, timeout) {
this.helpers.assertArgumentTimeout(timeout, 'timeout');
this.retryCount = 3;
this.firstError = null;

this.focusRetryCount = 3;
this.focusFirstError = null;

this.clickJS = async (el) => {
try {
/*global document*/
const retVal = await this.driver.execute(function(domEl) {
domEl.focus();
// createEvent won't be available in IE < 9 compatibility mode
if (!document.createEvent) {
if (document.createEventObject) {
Expand Down Expand Up @@ -65,11 +70,30 @@ module.exports = async function(locator, timeout) {
}
};

this.focus = async (el) => {
try {
await this.driver.execute(function(domEl) {
domEl.focus();
}, el);
} catch (e) {
if (this.focusRetryCount) {
if (!this.focusFirstError) {
this.focusFirstError = e;
}
--this.focusRetryCount;
await this.focus(el);
} else {
throw this.focusFirstError;
}
}
};

var el = await this.helpers.getElement(locator, false, timeout);

var clickable = await el.isClickable();
if (clickable) {
try {
await this.focus(el);
await el.click();
} catch (e) {
// chromedriver doesn't seem to support clicking on elements in Shadow DOM
Expand Down
20 changes: 14 additions & 6 deletions src/ox_modules/module-web/commands/clickHidden.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,25 @@
* @example <caption>[javascript] Usage example</caption>
* web.clickHidden("id=HiddenLink");
*/
module.exports = async function(locator, clickParent) {
module.exports = async function(locator, clickParent = false) {
this.helpers.assertArgumentBoolOptional(clickParent, 'clickParent');
this.retryCount = 3;
this.firstError = null;
this.clickJS = async (domEl, clickParent) => {
this.clickJS = async (domEl, clickParent = false) => {
try {
/*global document*/
const retVal = await this.driver.execute(function(domEl) {
const retVal = await this.driver.execute(function(domEl, clickParent) {
// createEvent won't be available in IE < 9 compatibility mode
if (!document.createEvent) {
if (document.createEventObject) {
var ev = document.createEventObject();
domEl.fireEvent('onclick', ev);
if (clickParent) {
domEl.parentElement.focus();
domEl.parentElement.fireEvent('onclick', ev);
} else {
domEl.focus();
domEl.fireEvent('onclick', ev);
}
} else {
return 'clickHidden is not supported on IE with compatibility mode "IE' +
document.documentMode + ' ' + document.compatMode + '"';
Expand All @@ -38,11 +44,13 @@ module.exports = async function(locator, clickParent) {
var clckEv = document.createEvent('MouseEvent');
clckEv.initEvent('click', true, true);
if (clickParent) {
domEl.parentElement.focus();
domEl.parentElement.dispatchEvent(clckEv);
} else {
domEl.focus();
domEl.dispatchEvent(clckEv);
}
}, el);
}, el, clickParent);

/*
{
Expand All @@ -63,7 +71,7 @@ module.exports = async function(locator, clickParent) {
this.firstError = e;
}
--this.retryCount;
await this.clickJS(el, domEl);
await this.clickJS(el, clickParent);
} else {
throw this.firstError;
}
Expand Down