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

Add isActive() command to new Element API #4261

Merged
merged 9 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 1 addition & 3 deletions lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ class ScopedWebElement {
this.webElement = promise;
} else {
this.webElement = new WebElementPromise(this.driver, this.then(async (element) => {
await promise;

return element;
return await promise;
garg3133 marked this conversation as resolved.
Show resolved Hide resolved
}));
}

Expand Down
4 changes: 4 additions & 0 deletions lib/transport/selenium-webdriver/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class TransportActions {
promise = Array.isArray(args) ? mapping.apply(this.MethodMappings, args) : mapping.call(this.MethodMappings, args);
}

if (promise.resolveEarly){
promise = await promise;
}

if (!(promise instanceof Promise)) {
const opts = {};

Expand Down
37 changes: 15 additions & 22 deletions lib/transport/selenium-webdriver/method-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,34 +493,27 @@ module.exports = class MethodMappings {
};
},

async getElementComputedRole(webElementOrId) {
const element = this.getWebElement(webElementOrId);

const role = await this.driver.executeScript(`
const el = arguments[0];
let role = el.getAttribute('role');
return role || 'unknown';
`, element);
getElementComputedRole(webElementOrId) {
const promise = (async () => {
const id = await webElementOrId.getId();

return {
value: role
};
return `/element/${id}/computedrole`;
})();
promise.resolveEarly = true;

return promise;
},

async getElementComputedLabel(webElementOrId) {
const element = this.getWebElement(webElementOrId);
getElementComputedLabel(webElementOrId) {
const promise = (async () => {
const id = await webElementOrId.getId();

const label = await this.driver.executeScript(`
const el = arguments[0];
let label = el.getAttribute('aria-label') ||
el.getAttribute('title') ||
el.getAttribute('alt');
return label || 'unknown';
`, element);
return `/element/${id}/computedlabel`;
})();
promise.resolveEarly = true;

return {
value: label
};
return promise;
},

async isElementActive(webElementOrId) {
Expand Down
Loading