2

Is there any way by which we can remove a web-element from the the source of the page.

I have the problem that there is a division of popup in the webpage source which is disabling all other divisions. If we remove this division while doing inspect element from a browser all other elements are automatically enabled for use.

How can I do this in selenium webdriver?

1
  • In general, it's a bad practice to modify the HTML of the page. Selenium was designed to interact with the page as a user would. What do you have to do manually to get to the elements that you want to interact with? Do that using code and you should be able to complete your scenario. Commented Nov 27, 2015 at 6:57

1 Answer 1

4

To my knowledge, there is no direct Java method, but you can use the JavaScriptExecutor API to do something like:

WebElement yourElement = …
JavaScriptExecutor jsExecutor = (JavaScriptExecutor) webDriver;
jsExecutor.executeScript(
    "arguments[0].parentNode.removeChild(arguments[0])", yourElement);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help. Actually I have solved my problem by clicking on a webelement (OK button). It worked for my case but wont work in general.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.