报错原因

元素不可交互,可能未渲染出来

解决办法

方法1: 交互前等待一会

  1. import time
  2. time.sleep(5)
  3. browser.find_element('id', 'submit').click()

方法2:

  1. from selenium.webdriver.support.ui import WebDriverWait
  2. from selenium.webdriver.support import expected_conditions as EC
  3. wait = WebDriverWait(browser, 30)
  4. wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input:nth-child(1)'))).click()
  5. wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'ul li:nth-child(3)'))).click()