#selenium如何实现遍历点击啊?
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import time
from selenium import webdriver
web =webdriver.Edge()
web.get('https://bk.wzxsjw.com/electronicbook')
time.sleep(3)
utllist1 =web.find_elements(By.CLASS_NAME,'coverDiv___rhKSe')
print(utllist1)
for element in utllist1:
#print(element)
element.click()
time.sleep(2)
returen=web.find_element(By.XPATH, '//*[@id="root"]/div/div/div[1]/div[2]/div[1]/img')
web.back()
time.sleep(2)#返回后,出现错误,不再点击?这是什么原因
‘’‘
Traceback (most recent call last):
File "D:\python笔记\云展网下载.py", line 15, in <module>
element.click()
File "C:\Users\liuji\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 94, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\liuji\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 403, in _execute
return self._parent.execute(command, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\liuji\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
self.error_handler.check_response(response)
File "C:\Users\liuji\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: stale element not found
(Session info: MicrosoftEdge=114.0.1823.43)
Stacktrace:
Backtrace:
GetHandleVerifier [0x00007FF77C83B582+64226]
Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF77C7CBB42+770978]