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 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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);
garg3133 marked this conversation as resolved.
Show resolved Hide resolved

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);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we use this endpoint to get the active element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this actually returns the active element, so we won't be able to get the element here to check if the element is that element only.


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