When using Selenium in Java, I am encountering issues changing the style
within a specific div
section. The goal is to modify the style
of the div
element with the id
of "navbar
". Please refer to the provided image for clarification.
Here is a brief snippet of the HTML structure:
This snippet demonstrates the code I have been attempting to use:
JavascriptExecutor js = null;
if (driver instanceof JavascriptExecutor)
{ js
= (JavascriptExecutor) driver;
}
WebElement element = driver.findElement(By.xpath("/html/body/div[1]"));
System.out.println(element);
//js.executeScript("arguments[0].setAttribute('style','display:none')", element);
js.executeScript("arguments[0].style.display = 'none'", element);