Selenium moveByOffset 不执行任何操作

2023-12-13

我在 Linux Xubuntu 13.10 上使用 Firefox 28.0 运行最新的 selenium 2.41

我试图让 FirefoxDriver 将鼠标移到页面上(在我的测试中,我使用了有线网页,它有很多悬停激活的菜单),但是moveByOffset根本没有做任何让鼠标注意到的事情:

package org.openqa.mytest;

import java.util.List;
import java.io.File;
import java.lang.*;

import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.interactions.*;

import org.apache.commons.io.FileUtils;

public class Example {
    public static void main(String[] args) throws Exception {
        // The Firefox driver supports javascript 
    FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(true);
        WebDriver driver = new FirefoxDriver(profile);

        // Go to the Google Suggest home page
        driver.get("http://www.wired.com");

    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        // now save the screenshto to a file some place
        FileUtils.copyFile(scrFile, new File("./screenshot.png"));


    Actions builder = new Actions(driver);
    Action moveM = builder.moveByOffset(40, 40).build();
    moveM.perform();

    Action click = builder.click().build();
    click.perform();
    //click.release();

    Action moveM2 = builder.moveByOffset(50, 50).build();
    moveM2.perform();

    Action click2 = builder.click().build();
    click2.perform();
    //click2.release();

    Action moveM3 = builder.moveByOffset(150, 540).build();
    moveM3.perform();

    for( int i=0; i < 1000; i++)
    {
        moveM = builder.moveByOffset(200, 200).build();
        moveM.perform();
        Thread.sleep(500);
        moveM = builder.moveByOffset(-200, -200).build();
        moveM.perform();
        Thread.sleep(500);
    }
    //Action click3 = builder.click().build();
    //click3.perform();
    //click3.release();

    scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        // now save the screenshto to a file some place
        FileUtils.copyFile(scrFile, new File("./screenshot2.png"));

        driver.quit();
    }
}

我期望鼠标移动到不同的元素上并触发所有悬停操作,但什么也没有发生


方法moveByOffset班级的Actions已损坏或已损坏。看Selenium WebDriver 错误 3578

(此错误文档中更详细地描述了该错误)。

项目成员 (barancev) 声称这个错误应该已在 Selenium 2.42 版本中修复。

尽管如此,我在 openSUSE 12.3 和 Firefox 33.0 上运行的 2.44 版本中发现了同样的错误。moveToElement works, moveToOffset没有。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Selenium moveByOffset 不执行任何操作 的相关文章

随机推荐