python-3.7 - selenium 和 python3 中没有发生鼠标悬停动作
问题描述
我正在使用 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()
解决方案
这可以使用 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)
推荐阅读
- android - 使用 Android Intent 启动带有查询字符串的 Amazon Alexa 应用程序
- sql - 有没有最简单的方法从 oracle 的电子邮件地址中只选择域名?
- javascript - 计算 li 元素的数量并添加类
- python-3.x - Python Selenium DOM Click 事件无法按预期工作
- java - Java Swing 验证?
- system-verilog - 转储 SystemVerilog 类的内存
- android - Flutter 中 ListView.builder 中的反向列表
- amazon-web-services - ALB 上的 504 网关超时
- java - 如何将模拟注入私有方法?
- r - 使用 approxm 函数插值一列出错