如何使用Selenium将style属性设置为element?

3 c# selenium selenium-webdriver

driver.SwitchTo().Frame("contentFrame");
IWebElement str = driver.FindElement(By.XPath("//*[@id='dvCustomDateRange']"));
Run Code Online (Sandbox Code Playgroud)

我需要将样式属性从style =“ display:none;”更改为 为style =“ display:block;”。

这是元素:

<div id="dvCustomDateRange" tabindex="0" class="filters hidden inline-block inlineChilds NoPrint width100 marginBt7" style="display: block;">

任何想法如何使用硒吗?我尝试使用getAttribute和getCssValue方法更改值,但没有结果。

Gra*_*per 5

您将必须使用javascript执行程序来设置css属性值。

IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.executeScript("arguments[0].style='display: block;'", element);
Run Code Online (Sandbox Code Playgroud)