【发布时间】:2022-08-17 22:08:17
【问题描述】:
代码试验:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import StaleElementReferenceException
from webdriver_manager.chrome import ChromeDriverManager
import time
# Find Search Element end Type Automation
search_bar = driver.find_element(By.XPATH, \"//input[@id=\'sb_form_q\']\")
search_bar.send_keys(\"Automation\")
time.sleep(3)
# Click Search Button
search_button = driver.find_element(By.XPATH, \"//label[@id=\'search_icon\']//*[name()=\'svg\']\")
search_button.click()
time.sleep(3)
# Clear Search Bar
search_bar.clear()
为什么当我尝试重用 search_bar(例如:search_bar.clear())时,我总是遇到问题:
StaleElementReferenceException Message: stale element reference: element is not attached to the page document
(会话信息:chrome=104.0.5112.81)
请帮忙。
错误快照:
错误快照:
标签: python selenium selenium-webdriver staleelementreferenceexception