我正在使用Selenium(3.12.0)和Pyhton(3.7)自动化Expedia网站。我无法实现鼠标悬停操作。 错误消息是:selenium.common.exceptions.ElementNotInteractableException:消息:无法将元素滚动到视图中 代码片段如下:-
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()
答案 0 :(得分:0)
这可以使用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)