我想知道如何删除 selenium python 中的元素,我想删除网站中的聊天框,就像您通过按退格键手动删除它一样,但我想在 selenium 中删除。到目前为止我已经试过了
chatBox = driver.find_element(By.XPATH, "//div[@class='chatContainer oldStyle']").remove()
这行代码报错
AttributeError: 'WebElement' object has no attribute 'remove'
任何帮助将不胜感激
最佳答案
我找到了解决办法,这是我用来修复它的代码
try:
element = driver.find_element_by_xpath("//div[@class='chatContainer oldStyle']")
driver.execute_script("""var element = arguments[0];
element.parentNode.removeChild(element);""", element)
except Exception:
pass
https://stackoverflow.com/questions/70222166/