問題描述
我想在 Facebook 廣告管理器中自動執(zhí)行一項簡單的任務(wù).此任務(wù)涉及設(shè)置活動和上傳一些廣告.人類可能需要 30 分鐘才能做到這一點.然而,他們每次都在做同樣的事情.經(jīng)常有錯誤.這應(yīng)該是自動化的.沒有人的情感或錯誤就完成了.
I want to automate a simple task inside Facebook Ads Manager. This task involves setting up a campaign and uploading some ads. It can take a human 30 minutes to do this. However, they're doing the same thing every single time. Often with mistakes. It's something that should be automated. Done without human emotion or mistakes.
Facebook 非常敏感,我不希望它因為錯誤的原因禁止我.所以我需要感受人性.我可以在點擊之間花時間.但是,光標移動本身需要感覺人性化.出于道德目的,我只需要模擬真實的人類點擊.
Facebook is very sensitive and I don't want it to ban me for the wrong reasons. So I need to feel human. I can take my time between clicks. However, the cursor movement itself needs to feel human. I only need to simulate a real human click for ethical purposes.
假設(shè)我得到了一個想要將光標移向的元素:
Say I get an element I want to move my cursor towards:
WebDriver driver;
// Set file path of chrome driver
System.setProperty("webdriver.chrome.driver", "C:\chromedriver.exe");
// Create object
ChromeDriver driver = new ChromeDriver(options);
// Go to URL
driver.get("FACEBOOK URL");
// Get element
driver.findElement(By.xpath("//span[contains(text(), 'Setup Campaign')]");
像真人一樣將光標移向該元素的最佳方法是什么?
What is the best way to move my cursor towards this element as a real human would?
真正的人類會首先移動鼠標.不只是點擊元素
A real human would first move the mouse. Not just click the element
他們會緩慢移動鼠標/光標.最多可能需要 500-1000 毫秒.當然不是立即.
They would move the mouse/cursor slowly. It could take up to say 500-1000 milliseconds. Certainly not instantly.
他們會以彎曲的方式移動鼠標/光標.不僅僅是100%的直線.可能,以隨機方式?那么可能需要一些隨機性元素?
They would move the mouse/cursor in a curved fashion. Not just in a 100% straight line. Possibly, in a random fashion? So some elements of randomness may be needed?
我對 Selenium 還是很陌生,因此我們將不勝感激.
I'm quite new to Selenium, so any input would be greatly appreciated.
我正在用 Java 編寫代碼 :)
I am writing my code in Java :)
推薦答案
WebDriver 不使用操作系統(tǒng)輸入;它通過http協(xié)議直接與瀏覽器通信.如果您想模擬像真實"鼠標輸入一樣的通信,您必須使用使用基于操作系統(tǒng)的框架的自動化解決方案.如果是 Windows,您可以使用例如:
WebDriver doesn't use an operating system input; it communicates directly with the browser via http protocol. If you want to simulate communication like a 'real' mouse input you have to use an automation solution that uses operating system based frameworks. In case of Windows you can use e.g.:
- https://github.com/FlaUI/FlaUI(閱讀https://github.com/FlaUI/FlaUI/wiki/FAQ 了解如何將 Chrome 配置為為 FlaUI 公開 Web 控件)
- https://github.com/microsoft/WinAppDriver
- https://github.com/FlaUI/FlaUI (read https://github.com/FlaUI/FlaUI/wiki/FAQ to get the knowledge how to configure Chrome to expose web controls for FlaUI)
- https://github.com/microsoft/WinAppDriver
這篇關(guān)于Selenium WebDriver/Java - 模擬人類光標移動的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!