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

Commit

Permalink
Merge pull request #68 from kevinlacotaco/hide-multiple-with-selector
Browse files Browse the repository at this point in the history
fix(hide-remove): use querySelectorAll, mark visited to not repeat
  • Loading branch information
wswebcreation committed May 2, 2020
2 parents 5982b0a + b16c311 commit 61bf8d4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/clientSideScripts/hideRemoveElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function hideRemoveElements(
},
hideRemove: boolean): any {

const visitedSelectors: Record<string, boolean> = {};
hideRemoveElements.hide.forEach(element => {
if (Array.isArray(element)) {
return element.forEach((singleElement: HTMLElement | WebElement) => hideRemoveEl(singleElement, 'visibility', hideRemove));
Expand All @@ -36,12 +37,14 @@ export default function hideRemoveElements(
// css and xpath, transform them into HTML
// This is an anti pattern, but I don't know how to do this better with XPATH selection
try {
if (singleElement) {
// @ts-ignore
setPropertyToElement(document.querySelector(el.selector), prop, hideRemove);
} else {
// @ts-ignore
document.querySelectorAll(el.selector).forEach(singleEl =>
// @ts-ignore
const selector = el.selector;

if (visitedSelectors[selector] == null) {
visitedSelectors[selector] = true;
const elems = document.querySelectorAll(selector);

elems.forEach(singleEl =>
setPropertyToElement(singleEl, prop, hideRemove)
);
}
Expand Down

0 comments on commit 61bf8d4

Please sign in to comment.