Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am trying to set style of a div element using JavascriptExecutor using C#.
below is the code i tried but nothing happens
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
IWebElement element = driver.FindElement(By.XPath("//div[contains(@class,'rmSlide')]"));
js.ExecuteScript("arguments[0].setAttribute(arguments[1], arguments[2])",
element, "style",
"visibility: visible;
height: 259px;
width: 339px;
display: block;
overflow: hidden;
left: -81px;
top: 24px;
z-index: 2; "
All I am trying to do is setting the display: block
from display: none
Below is the Html of the element
As you are trying to change the attribute display: none;
to display: block;
you can use the following code block :
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
IWebElement element = driver.FindElement(By.XPath("//div[contains(@class,'rmSlide')]"));
var script = "arguments[0].style.display='block';";
js.ExecuteScript(script, element);
–
–
–
–
–
I got the code right, just modified and added mouse hover on the element, below is the code.
var element = driver.FindElement(By.XPath("xpathe here"));
Actions action = new Actions(driver);
action.MoveToElement(element).Build().Perform();
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
IWebElement element1 = driver.FindElement(By.XPath("//div[contains(@class,'rmSlide')]"));
js.ExecuteScript("arguments[0].setAttribute('style', 'visibility: visible; height: 259px; width: 339px; display: block; overflow: hidden; left: -81px; top: 24px; z - index: 2; ')", element1);
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.