Skip to content
This repository has been archived by the owner on Dec 24, 2023. It is now read-only.

Commit

Permalink
fix: fix issue 52
Browse files Browse the repository at this point in the history
- webelements needed to be converted to html elements
- add webdriver types
  • Loading branch information
wswebcreation committed Feb 29, 2020
1 parent eff7715 commit 53917a0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
36 changes: 26 additions & 10 deletions lib/clientSideScripts/hideRemoveElements.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
import {WebElement} from 'selenium-webdriver';

/**
* Hide or remove elements on the page
*/
export default function hideRemoveElements(
hideRemoveElements:
{
hide: (HTMLElement | HTMLElement[])[],
hide: (HTMLElement | HTMLElement[] | WebElement | WebElement[])[],
remove: (HTMLElement | HTMLElement[])[],
},
hideRemove: boolean): void {
hideRemove: boolean): any {

hideRemoveElements.hide.forEach(element => {
if (Array.isArray(element)) {
return element.forEach(singleElement => {
singleElement.style.visibility = hideRemove ? 'hidden' : '';
});
return element.forEach((singleElement: HTMLElement | WebElement) => hideRemoveEl(singleElement, 'visibility', hideRemove));
}

return element.style.visibility = hideRemove ? 'hidden' : '';
hideRemoveEl(element, 'visibility', hideRemove, true);
});

hideRemoveElements.remove.forEach(element => {
if (Array.isArray(element)) {
return element.forEach(singleElement => singleElement.style.display = hideRemove ? 'none' : '');
return element.forEach((singleElement: HTMLElement | WebElement) => hideRemoveEl(singleElement, 'display', hideRemove));
}

return element.style.display = hideRemove ? 'none' : '';
hideRemoveEl(element, 'display', hideRemove, true);
});

function hideRemoveEl(el: HTMLElement | WebElement, prop: string, hideRemove: boolean, singleElement: boolean = false) {
const value = prop === 'visibility' ? 'hidden' : 'none';
try {
// Here we get the HTMLElement, if this fails we have a WebElement
// @ts-ignore
el.style[prop] = hideRemove ? value : '';
} catch (e) {
/// Here we have the WebElement
if (singleElement) {
// @ts-ignore
return document.querySelector(el.selector).style[prop] = hideRemove ? value : '';
}

// @ts-ignore
return document.querySelectorAll(el.selector).forEach(singleEl => singleEl.style[prop] = hideRemove ? value : '');
}
}
}
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"homepage": "https://github.com/wswebcreation/webdriver-image-comparison#readme",
"dependencies": {
"@types/selenium-webdriver": "^4.0.8",
"canvas": "^2.6.1",
"chalk": "^3.0.0",
"fs-extra": "^8.1.0"
Expand Down

0 comments on commit 53917a0

Please sign in to comment.