hide element selenium

hide element selenium

In Selenium, you can use the WebDriver's executeScript() method to hide an element by modifying its style.

Here's an example of how to hide an element with Selenium:

WebDriver driver = new ChromeDriver();
driver.get("http://example.com");

// Find the element to hide
WebElement element = driver.findElement(By.id("my-element"));

// Hide the element
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].style.display='none'", element);
Source:‮w‬ww.lautturi.com

In this example, we are using the executeScript() method to execute a JavaScript command that sets the display property of the element's style to 'none', which hides the element.

You can also use the executeScript() method to show an element that was previously hidden by setting the display property to 'block' or 'inline', depending on the element's type.

Created Time:2017-11-01 12:05:08  Author:lautturi