藉助 Selenium 創造類人化滑鼠移動。
我們可以藉助 Selenium 實現類人化的滑鼠移動。可以藉助 Actions 類進行此操作。類人化的滑鼠移動包括右鍵單擊、雙擊、滑鼠移動、拖放操作等。
要進行滑鼠移動,請使用 moveToElement 方法。要執行右鍵單擊操作,請使用 contextClick 方法。最後,要真正執行操作,應新增 build 和 perform 方法。

一旦我們右鍵單擊一個元素,就會顯示各種選項。我們必須新增** import org.openqa.selenium.interactions.Actions 包來實現操作。
示例
程式碼實現。
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
public class RightClick{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
String u = " https://tutorialspoint.tw/about/about_careers.htm";
driver.get(u);
// identify element
WebElement m=driver.findElement(By.xpath("//*[text()='Careers']"));
// moveToElement and contextClick
Actions act = new Actions(driver);
act.moveToElement(m).contextClick().build().perform();
}
}輸出

廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C #
MongoDB
MySQL
JavaScript
PHP