Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  167] [ 5]  / answers: 1 / hits: 39647  / 10 Years ago, wed, march 19, 2014, 12:00:00

I've been trying the last hour to delete an element by without any success. And the element can only be reached via class name.
I've tried:



js = var aa=document.getElementsByClassName('classname')[0];aa.parentNode.removeChild(aa)
driver.execute_script(js)


I get error that parentNode is undefined.



So what the best way to delete an element using Selenium?


More From » python

 Answers
52

getElementByClassName is not a method on document. You'll want to use



getElementsByClassName('classname')[0]...


but only if you're sure it's the only one with that class.


[#71899] Tuesday, March 18, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mustafaericho

Total Points: 322
Total Questions: 103
Total Answers: 110

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
mustafaericho questions
Mon, May 31, 21, 00:00, 3 Years ago
Sun, May 23, 21, 00:00, 3 Years ago
Sat, Feb 13, 21, 00:00, 3 Years ago
Sat, Jan 2, 21, 00:00, 3 Years ago
Thu, Nov 12, 20, 00:00, 4 Years ago
;