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);
要将样式属性的display
属性设置为block
您可以使用:
((JavascriptExecutor) driver).executeScript("document.getElementById('navbar').style.display='block';");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.