当driver.send_keys(Keys.ENTER)不工作时,可能是由于以下几个原因导致的:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, 'xpath_of_element'))
)
element.click()
driver.execute_script("arguments[0].dispatchEvent(new KeyboardEvent('keydown', {key: 'Enter'}));", element)
以上是修复driver.send_keys(Keys.ENTER)不工作的一些常见方法。根据具体情况选择适合的方法进行修复。
领取专属 10元无门槛券
手把手带您无忧上云