0

我正在使用 selenium(3.12.0) 和 Pyhton(3.7) 自动化 Expedia 网站。我无法实现鼠标悬停动作。错误信息是:selenium.common.exceptions.ElementNotInteractableException: Message: Element could not be scrolled into view 代码片段如下:-

driver = webdriver.Firefox()
driver.delete_all_cookies()
driver.get("https://www.expedia.com/")
driver.maximize_window()
driver.set_page_load_timeout(20)
driver.find_element_by_id("tab-flight-tab-hp").click()
driver.find_element_by_id("flight-type-one-way-label-hp-flight").click()
driver.find_element(By.ID, "flight-origin-hp-flight").send_keys("pnq")
driver.find_element(By.ID, "flight-destination-hp-flight").send_keys("ccu")
dep_time = driver.find_element(By.ID, "flight-departing-single-hp-flight")
act = ActionChains(driver)
dep_time.send_keys("03/10/2019")
act.move_to_element(dep_time).click(dep_time).perform()
driver.find_element_by_xpath("//*[@id='search-button-hp-package']").click()
driver.quit()
4

1 回答 1

1

这可以使用 JavascriptExecutor 来实现。

driver.find_element_by_id("tab-flight-tab-hp").click()
driver.find_element_by_id("flight-type-one-way-label-hp-flight").click()
driver.find_element(By.ID, "flight-origin-hp-flight").send_keys("pnq")
driver.find_element(By.ID, "flight-destination-hp-flight").send_keys("ccu")
driver.find_element(By.ID, "flight-departing-single-hp-flight").send_keys("03/10/2019") 
button = driver.find_element_by_xpath("//*[@id='search-button-hp-package']")
driver.execute_script("arguments[0].click();", button)
于 2019-03-17T15:05:11.330 回答