[英]How to Set style property to element using Selenium?
driver.SwitchTo().Frame("contentFrame");
IWebElement str = driver.FindElement(By.XPath("//*[@id='dvCustomDateRange']"));
I need to change the style attribute from style="display: none;"我需要从 style="display: none;" 更改样式属性to style="display: block;".样式=“显示:块;”。
This is the element:这是元素:
<div id="dvCustomDateRange" tabindex="0" class="filters hidden inline-block inlineChilds NoPrint width100 marginBt7" style="display: block;">
any idea how to do this using Selenium?知道如何使用硒来做到这一点吗? Im try getAttribute and getCssValue methods to change value but without result.我尝试 getAttribute 和 getCssValue 方法来更改值但没有结果。
You will have to use javascript executor to set a css attribute value.您必须使用 javascript 执行程序来设置 css 属性值。
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.executeScript("arguments[0].style='display: block;'", element);
executeScript() 会做到这一点:
driver.executeScript("arguments[0].style='display: block;'",element);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.