简体   繁体   English

如何使用 Selenium 和 Java 更改元素的样式属性的显示属性

[英]How to change the display property of the style attribute of an element using Selenium and Java

I am not able to change the style in div section using selenium Java .我无法使用 selenium Java更改div部分中的style Please see picture I need to change the style of div which contain id is " navbar ".请看图片 我需要更改包含iddiv style为“ navbar ”。

Snapshot of the HTML: HTML 的快照:

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';");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Python 和 Selenium 更改元素的 class 属性的值 - How to change the value of the class attribute of an element using Python and Selenium 使用JavaScript更改div的显示样式属性 - Change display style property of a div using Javascript 查找具有样式属性的元素并进行更改 - Find element with style attribute and change it 如何从具有属性style =“ display:none;的元素中提取文本; - How to extract text from element with attribute style="display:none; 如何使用javascript使用java使用selenium Webdriver设置所选Web元素的属性? - How to use javascript to set attribute of selected web element using selenium Webdriver using java? (JavaScript / HTML)如何在单击按钮时更改样式属性的显示? - (JavaScript / HTML) How to change display in style attribute on button click? 如何在IE中使用'contenteditable'属性更改元素上的光标样式? - How to change cursor style on element with 'contenteditable' attribute in IE? 如何使用jQuery更改CSS元素的样式 - how to change style of a css element using jQuery React:如何根据另一个 JSX 元素更改样式属性? - React: how to change the style property of one JSX element based on another? 无法读取未定义错误的属性“ setValue”。 如何使用Selenium WebDriver和Java在codeMirror元素中键入文本? - Cannot read property 'setValue' of undefined error. How to type text in codeMirror element using Selenium WebDriver and Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM