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 additional commands for new Element API #4261

Open
wants to merge 2 commits into
base: main
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
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);
Comment on lines +499 to +503
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the endpoint directly instead of executing script here.


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
6 changes: 6 additions & 0 deletions types/web-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {

isVisible(): ElementValue<boolean>;
isDisplayed(): ElementValue<boolean>;

isActive(): ElementValue<boolean>;

getComputedLabel(): ElementValue<string>;

getComputedRole(): ElementValue<string>;
}

type WaitUntilOptions = {
Expand Down
Loading