Set Invisible Element to Visible Using Javascript in Selenium

Automation with selenium requires target element to be set visible.
While when element is designed to be displayed: none or visibility = hidden,  we have to manually set element css style to be visible using Javascript for selenium to catch on.

Here is the code:

IWebElement checkbox = driver.FindElement(By.Id("identifierOrOther"));
IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
executor.ExecuteScript("arguments[0].style.display = 'block'", checkbox);

style.display = block can be replaced any other code, just inspect the hidden element and find out hidden css line.

No comments:

Post a Comment

Setup VNC on Ubuntu 20.04

  sudo apt update sudo apt install xfce4 xfce4-goodies sudo apt install tigervnc-standalone-server sudo apt install tightvncserver vncserver...