I am attempting to set an attribute
value for all instances of the same type of <img>
tag on My website, for example:
<img src="images/temp/advertisement.png">
and I want to set style="display: none"
so that I can hide them.
I have tried the following method -
List<WebElement> element = driver.findElements(By.tagName("img"));
for(WebElement e:element)
{
if(e.getAttribute(src).contains("images/temp/advertisement.png"))
{
jse.executeScript("document."+e+".setAttribute('style', 'display: none;')");
}
}
but I'm encountering an error
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Runtime.evaluate threw exception: SyntaxError: Unexpected token [
Can anyone help me figure out what is wrong here or suggest another approach?