借助 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.com/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