gpt4 book ai didi

ruby - 在 ruby​​ Selenium 中移动鼠标(move_to)

转载 作者:数据小太阳 更新时间:2023-10-29 07:06:40 24 4
gpt4 key购买 nike

我正在尝试使用 Ruby 中的 Selenium WebDriver 2.4 模拟鼠标移动

如果我运行测试,是否应该看到鼠标在我的屏幕上移动?我很困惑。

我试过很多不同的方法示例代码:

require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
driver.navigate.to 'http://www.google.com'
element = driver.find_element(:id, 'gbqfba')

那我试过了

driver.action.move_to(element).perform
driver.mouse.move_to(element)

还有 Watir 的悬停方法。

到目前为止,我发现的最佳方法是 Watir 的 fire_event 'onmouseover'但是仍然没有移动鼠标:)

在 SO 和其他地方搜索之后,我似乎无法在 WebDriver 中移动鼠标。

发生了什么事?是否有可能在屏幕上实际移动鼠标光标(当 webdriver 浏览器窗口在 View 中时)

最佳答案

答案是 您不会在视觉上看到您的鼠标移动。 Selenium 在内部与页面交互,这意味着它不会使用您的桌面鼠标。

如果您担心它不起作用,那么您可能操作了错误的元素,因为 driver.action.move_to(element).performvalid .

关于ruby - 在 ruby​​ Selenium 中移动鼠标(move_to),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22541934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com