gpt4 book ai didi

firefox - 使用 Selenium 记录 Action

转载 作者:行者123 更新时间:2023-12-04 03:30:03 25 4
gpt4 key购买 nike

关于 Selenium ,我有一个模糊的问题要问。我发现了几种不同的方法来使用FirefoxDriver执行操作。我需要做的是重复用户在网页上执行的操作(单击链接,选中复选框等)。是否有任何方法或方法组合可以让我“记录”用户的操作?到目前为止,这是我执行 Action 的内容(您会注意到我已经尝试过使用WebDriverBackedSelenium和Actions类执行 Action )

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.Action;

public class MyReplayer {
public static void main(String[] args) throws Exception {
// The Firefox driver supports javascript
FirefoxDriver driver = new FirefoxDriver();

driver.get("http://www.cs.umd.edu");

List<WebElement> elements = driver.findElements(By.tagName("a"));
//WebDriverBackedSelenium driverBacked = new WebDriverBackedSelenium(driver, "http://www.cs.umd.edu");
Actions builder = new Actions(driver);
Action clickLink = builder.click(elements.get(100)).build();
clickLink.perform();
//driverBacked.click("document.getElementsByTagName('a')[100]");
}
}

最佳答案

我碰到Huxley。它允许记录和回放用户 Action 。我找到了这个问题来寻找他们是如何做到的,但是不得不求助于源代码。

huxley/run.py的第98-154行定义了记录功能。它使用webdirvier在页面上执行一些js,从而添加了一些事件监听器。它还添加了一个返回事件的函数。

(function() {
var events = [];
window.addEventListener('click', function (e) { events.push([Date.now(), 'click', [e.clientX, e.clientY]]); }, true);
window.addEventListener('keyup', function (e) { events.push([Date.now(), 'keyup', String.fromCharCode(e.keyCode)]); }, true);
window._getHuxleyEvents = function() { return events; };
})();

要读取事件,请调用js函数
events = d.execute_script('return window._getHuxleyEvents();')

然后,事件以一种似乎是特定于应用程序的方式存储。

抱歉,我没有Java代码。我希望这有帮助。

关于firefox - 使用 Selenium 记录 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9880561/

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