这是selenium比较常见的报错,所以记录一下解决方法,避免总是忘记。
代码示例:
from os import times
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common import exceptions as selenium_ex
import time
from selenium.webdriver.common import by
# 问题部分代码:
click1 = wd1.find_elements_by_xpath(div1)
time.sleep(1.5)
wd1.execute_script("arguments[0].click();", click1)
分析原因
通过debug可以发现,click1并不是一个WebElement,而是一个list
解决方法:
所以把click1改成click1[0],就可以了