简体   繁体   English

我已经导入了 org.openqa.selenium.interactions.Actions 但仍然抛出错误 Actions can not resolve to a variable

[英]I have imported org.openqa.selenium.interactions.Actions but still throwing error Actions can not resolved to a variable

Showing Actions can not be resolved to a variable.显示操作无法解析为变量。

I am working on Mouse movement and creating object of Actions class.I have already imported org.openqa.selenium.interactions.Actions.我正在研究鼠标移动并创建动作 class 的 object。我已经导入了 org.openqa.selenium.interactions.Actions。 But still the error exist.I have tried following options:但仍然存在错误。我尝试了以下选项:

1.Restart, 2.Close and open project 3.Refresh 4.Clean 1.重启,2.关闭并打开项目 3.刷新 4.清理

Please help me into this请帮我解决这个问题

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();
        }

You need to add selenium-api library to your project CLASSPATH in order to be able to use Actions class.您需要将selenium-api库添加到您的项目CLASSPATH以便能够使用Actions class。

I would strongly recommend using a build system like Maven or Gradle which provides automatic dependencies management so you could declare selenium-java and testng as your project dependencies and the remaining ones would be automatically resolved by Maven or Gradle. I would strongly recommend using a build system like Maven or Gradle which provides automatic dependencies management so you could declare selenium-java and testng as your project dependencies and the remaining ones would be automatically resolved by Maven or Gradle.

在此处输入图像描述

Example Maven pom.xml file:示例 Maven pom.xml文件:

<?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>

Check out Selenium with Java article for comprehensive information and example project which you can use as the reference or skeleton for your tests.查看Selenium 和 Java文章以获取综合信息和示例项目,您可以将其用作测试的参考或框架。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到错误“org/openqa/selenium/interactions/HasInputDevices” - Getting error "org/openqa/selenium/interactions/HasInputDevices" “HasInputDevices”位于“/ org / openqa / selenium / interactions”但它仍然在查看“/ org / openqa / selenium /” - “HasInputDevices” is located at “/org/openqa/selenium/interactions” but it is still looking at “/org/openqa/selenium/” Firefox - org.openqa.selenium.interactions.MoveTargetOutOfBoundsException - Firefox - org.openqa.selenium.interactions.MoveTargetOutOfBoundsException Selenium webdriver:org.openqa.selenium.InvalidElementStateException:元素已禁用,因此可能无法用于操作 - Selenium webdriver :org.openqa.selenium.InvalidElementStateException: Element is disabled and so may not be used for actions 获取错误java.lang.NoClassDefFoundError:org / openqa / selenium / interactions / internal / Locableable在com.tests - Getting error java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/internal/Locatable at com.tests Selenium 程序抛出编译错误 org.openqa.selenium.internal.Killable 无法解析 - Selenium program throws compilation error org.openqa.selenium.internal.Killable cannot be resolved Selenium web驱动程序moveToElement(Actions)使用木偶驱动程序抛出错误? - Selenium web driver moveToElement (Actions) throwing error with marionette driver? java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/internal/Locatable 在 Ubuntu 14.04 上打开浏览器窗口后返回错误 - java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/internal/Locatable error is returned after browser window is opened on Ubuntu 14.04 java.lang.ClassCastException: org.openqa.selenium.firefox.FirefoxDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen - java.lang.ClassCastException: org.openqa.selenium.firefox.FirefoxDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen 导入 org.openqa.selenium.webdriver 无法解析 - the import org.openqa.selenium.webdriver cannot be resolved
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM