I'm using Selenium WebDriver(ChromeDriver). I need to remove some elements from page after processing(from DOM model).
For example I have a following element:
WebElement starRatingElement = reviewElement.findElement(By.className("review-info-star"));
How to remove starRatingElement
from browser DOM model ?
How it can be achieved in Java with Selenium WebDriver ? Please show an example.
We can delete an element in Selenium webdriver using Python with the help of JavaScript Executor. Selenium is not capable of modifying the structure of DOM directly. It has the feature of injecting JavaScript into the webpage and changing the DOM with the help execute_script method.
Removing an element using the removeChild() method First, select the target element that you want to remove using DOM methods such as querySelector() . Then, select the parent element of the target element and use the removeChild() method.
You'll have to execute a JavaScript code to make any DOM changes.
WebDriver driver = new ChromeDriver(); JavascriptExecutor js; if (driver instanceof JavascriptExecutor) { js = (JavascriptExecutor) driver; } js.executeScript("return document.getElementsByClassName('review-info-star')[0].remove();");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With