This repository has been archived by the owner on Dec 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- webelements needed to be converted to html elements - add webdriver types
- Loading branch information
1 parent
eff7715
commit 53917a0
Showing
3 changed files
with
32 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 : ''); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters