就是前端元素不存在,具体为什么不存在要具体分析了。可能是没加载出来,可能是前端对元素处理了。
显式设置对元素等待试试看
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
localBy = (By.CSS_SELECTOR, "#ls_username",)
until = EC.presence_of_element_located(localBy)
element = WebDriverWait(driver, 10).until(until)
element.send_keys('admin')
# TOOD
# ...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…