我正在尝试自动化在 Decentraland 中的移动过程(元节https://decentraland.org/)。在我自动化注册过程和一切之后,我跳入土地,但使用时actions.moveToElement(element, x, y);
,没有错误显示,但由于某种原因它不会移动 Decentraland 的屏幕。
这是代码
package com.example;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import java.util.concurrent.TimeUnit;
/**
* Hello world!
*/
public final class App {
/**
* Says hello to the world.
* @param args The arguments of the program.
*/
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://play.decentraland.org/?position=45%2C19&realm=fenrir-amber");
Dimension targetSize = new Dimension(800, 600);
driver.manage().window().setSize(targetSize);
sleep(1);
driver.findElement(By.xpath("//*[@id=\"eth-login-confirmation-wrapper\"]/button[2]")).click();
sleep(30);
// avatar section
Actions actions = new Actions(driver);
WebElement element = driver.findElement(By.xpath("//*[@id=\"#canvas\"]"));
sleep(5);
actions.moveToElement(element, 333, 210).click().perform();
// create profile section
actions = new Actions(driver);
element = driver.findElement(By.xpath("//*[@id=\"#canvas\"]"));
sleep(5);
actions.moveToElement(element, 130, -53).click().perform();
new Actions(driver).sendKeys("a").perform();
actions.moveToElement(element, 138, 103).click().perform();
// tos section
actions = new Actions(driver);
element = driver.findElement(By.xpath("//*[@id=\"#canvas\"]"));
sleep(5);
actions.moveToElement(element, 283, -99).clickAndHold().perform();
sleep(5);
actions.moveToElement(element, 283, 58).release().perform();
sleep(5);
actions.moveToElement(element, 140, 97).click().perform();
// click got it button in land
// 0, 166
actions = new Actions(driver);
element = driver.findElement(By.xpath("//*[@id=\"#canvas\"]"));
sleep(5);
actions.moveToElement(element, 0, 166).click().perform();
// pan shot
actions = new Actions(driver);
element = driver.findElement(By.xpath("//*[@id=\"#canvas\"]"));
sleep(5);
actions.moveToElement(element).click().perform();
sleep(5);
actions.moveToElement(element).doubleClick().perform();
sleep(5);
for (int i=1; i<5; i++) {
actions.moveToElement(element, 0, 10 * i).click().perform();
}
}
public static void sleep(int seconds) {
try {
internalSleep(seconds);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void internalSleep(int seconds) throws InterruptedException {
TimeUnit.SECONDS.sleep(seconds);
Thread.sleep((long)seconds * 1000);
}
public static void print(String message) {
System.out.println(message);
}
}
任何帮助将不胜感激。谢谢你。