【发布时间】:2022-01-04 17:10:52
【问题描述】:
我正在尝试从消息中清除我的 Instagram 聊天。我为此编写了以下代码,但是当我尝试删除第二条消息时,在threeDots 初始化行上出现了NoSuchElementException,尽管xpath 本身已正确编写。
if len(positionsArray) > 1:
for i in range(len(chatMessagesArray)):
# Click on three dots (else button)
threeDotsXpath = browser.find_element_by_xpath(f"/html/body/div[1]/section/div/div[2]/div/div/div[2]/div[2]/div/div[1]/div/div/div[{positionsArray[len(positionsArray) - 1] + 1}]/div[2]/div/div/div/button[1]").click()
# Deleting message and confirmation of it
deleteMessageDiv = browser.find_element_by_xpath(f"/html/body/div[1]/section/div/div[2]/div/div/div[2]/div[2]/div/div[1]/div/div/div[{positionsArray[len(positionsArray) - 1] + 1}]/div[2]/div/div/div/div[2]/div/div[2]/div[4]/button").click()
browser.find_element_by_xpath("/html/body/div[6]/div/div/div/div[2]/button[1]").click()
positionsArray.remove(positionsArray[len(positionsArray) - 1])
消息:没有这样的元素:无法找到元素: {"method":"xpath","selector":"/html/body/div[1]/section/div/div[2]/div/div/div[2]/div[2]/div/div [1]/div/div/div[2]/div[2]/div/div/div/button[1]"}
【问题讨论】: