Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我已经导入了org.openqa.selenium.interactions.Actions,但仍然抛出错误操作无法解析为变量_Java_Selenium - Fatal编程技术网

Java 我已经导入了org.openqa.selenium.interactions.Actions,但仍然抛出错误操作无法解析为变量

Java 我已经导入了org.openqa.selenium.interactions.Actions,但仍然抛出错误操作无法解析为变量,java,selenium,Java,Selenium,显示操作不能解析为变量 我正在研究鼠标移动和创建Actions类的对象。我已经导入了org.openqa.selenium.interactions.Actions。但错误仍然存在。我尝试了以下选项: 1.重新启动, 2.关闭和打开项目 3.刷新 4.清洁 请帮我解决这个问题 package storeFront; import org.testng.annotations.Test; import org.openqa.selenium.By; import org.o

显示操作不能解析为变量

我正在研究鼠标移动和创建Actions类的对象。我已经导入了org.openqa.selenium.interactions.Actions。但错误仍然存在。我尝试了以下选项:

1.重新启动, 2.关闭和打开项目 3.刷新 4.清洁

请帮我解决这个问题

package storeFront;
    import org.testng.annotations.Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.interactions.Actions;

public class WithTestNG {


@Test(priority = 0)
        public void OpenStore() {
    String exePath = "C:\\Users\\Downloads\\chromedriver_win32\\chromedriver.exe";
            System.setProperty("webdriver.chrome.driver","C:\\Users\\Downloads\\chromedriver_win32\\chromedriver.exe" );
            WebDriver driver = new ChromeDriver();

            String URL = "https://facebook.com";

            driver.get(URL);

            Actions action = new Actions(driver);
            action.moveToElement(driver.findElement(By.xpath("a#top-bar-menu.search-dropdown.ng-binding")).build().perform();
        }
您需要将库添加到项目中,以便能够使用类

我强烈建议使用像or这样的构建系统,它提供了自动功能,因此您可以将
selenium java
testng
声明为您的项目依赖项,其余的依赖项将由Maven或Gradle自动解析

Maven文件示例:


4.0.0
com.example

文章提供了全面的信息和示例项目,您可以将其用作测试的参考或框架。

我很好奇,没有导入
WebDriver
ChromeDriver
,您是如何管理的?
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>java-selenium-maven</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.0.0</version>
        </dependency>
    </dependencies>

</project>