相关文章推荐
直爽的围巾  ·  讲解selenium 获取href ...·  4 月前    · 
俊秀的海龟  ·  Selenium 函式庫 - Python ...·  4 月前    · 
坚强的柿子  ·  js循环生成表格-掘金·  2 年前    · 
帅呆的韭菜  ·  JS ...·  2 年前    · 
安静的包子  ·  jest 是如何 mock ...·  3 年前    · 

如何在Selenium python中删除一个元素

2 人关注

我想知道如何在Selenium python中删除一个元素,我想在一个网站中删除一个聊天框,就像你手动按退格键那样,但我想在Selenium中这样做。到目前为止,我已经尝试了以下方法

chatBox = driver.find_element(By.XPATH, "//div[@class='chatContainer oldStyle']").remove()

This line of code gives the error

AttributeError: 'WebElement' object has no attribute 'remove'

如果有任何帮助,我们将非常感激

python
selenium
stinkiepinkie
stinkiepinkie
发布于 2021-12-04
2 个回答
stinkiepinkie
stinkiepinkie
发布于 2021-12-04
已采纳
0 人赞同

我找到了一个解决方案,这是我用来解决这个问题的代码

element = driver.find_element_by_xpath("//div[@class='chatContainer oldStyle']") driver.execute_script("""var element = arguments[0]; element.parentNode.removeChild(element);""", element) except Exception: