I am trying to remove all the elements with the class "RemoveByMe", by executing javascript on an open browser. I previously created those elements myself.
I'm calling that javascript from Python: Selenium controls the browser, and sends the javascript to the open browser. But I think the problem relies on the javascript side, reasons on the next lines.
The python code for executing each script is:
Browser.execute_script("script here")
So far I have tried the following javascript code:
$('.RemoveByMe').remove();
This one gives the following error message:
#WebDriverException: Message: u'$ is not defined' ; Stacktrace:
at anonymous
This error seems to come from the python side, so I have tested more javascript code:
var DocElements = document.getElementsByTagName('RemoveByMe');for(var i = 0; i < DocElements.length; i++){DocElements[i].parentNode.removeChild(DocElements[0]);}
This one doesnt throw any errors (confirming that the python side is working), but still doesnt remove the elements. (javascript is not being able to remove them)
All of the tested javascript code works in some websites, but it doesnt in some others. That makes me think that the problem resides in the website, preventing the javascript from removing elements. (Although I could successfully add them)
How could I skip that prevention?