Skip to content

Commit

Permalink
Add additional commands for new Element API stash
Browse files Browse the repository at this point in the history
  • Loading branch information
dikwickley committed Sep 1, 2024
1 parent e06fd65 commit 7e11eb1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/api/web-element/commands/getComputedLabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.command = function () {
return this.runQueuedCommand('getElementComputedLabel');
};
3 changes: 3 additions & 0 deletions lib/api/web-element/commands/getComputedRole.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.command = function () {
return this.runQueuedCommand('getElementComputedRole');
};
3 changes: 3 additions & 0 deletions lib/api/web-element/commands/isActive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.command = function () {
return this.runQueuedCommandScoped('isElementActive');
};
41 changes: 41 additions & 0 deletions lib/transport/selenium-webdriver/method-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,47 @@ 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);

return {
value: role
};
},

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

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 {
value: label
};
},

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

const isActive = await this.driver.executeScript(`
const el = arguments[0];
return el === document.activeElement;
`, element);

return isActive;
},

async setElementProperty(webElementOrId, name, value) {
const element = this.getWebElement(webElementOrId);

Expand Down

0 comments on commit 7e11eb1

Please sign in to comment.