[英]Getting error "org/openqa/selenium/interactions/HasInputDevices"
[英]I have imported org.openqa.selenium.interactions.Actions but still throwing error Actions can not resolved to a variable
顯示操作無法解析為變量。
我正在研究鼠標移動並創建動作 class 的 object。我已經導入了 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();
}
您需要將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.
示例 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>
查看Selenium 和 Java文章以獲取綜合信息和示例項目,您可以將其用作測試的參考或框架。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.