Reputation: 1
I am not able to change the style
in div
section using selenium Java. Please see picture I need to change the style
of div
which contain id
is "navbar
".
Snapshot of the HTML:
This is my code:
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);
Upvotes: 0
Views: 1217
Reputation: 193088
To set the display
property of style attribute as block
you can use:
((JavascriptExecutor) driver).executeScript("document.getElementById('navbar').style.display='block';");
Upvotes: 1