Python selenium,我该如何删除元素? [英] Python selenium, how can i delete an element?
本文介绍了Python selenium,我该如何删除元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试最后一小时删除一个元素而没有任何成功。元素只能通过类名来访问。
我试过:
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得到错误,即parentNode未定义。
I get error that parentNode is undefined.
那么使用Selenium删除元素的最佳方法是什么?
So what the best way to delete an element using Selenium?
推荐答案
getElementByClassName不是文档
上的方法。你想要使用
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.
这篇关于Python selenium,我该如何删除元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文