我无法使findElement
方法在最新的WebDriver
(v2.52(中工作。已导入所有必需的类。这是我收到的错误 -
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.By.findElement(Lorg/openqa/selenium/SearchContext;)Lorg/openqa/selenium/WebElement;
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
at Flipkart_Test.main(Flipkart_Test.java:38)
我正在运行的代码是 -
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.*;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import java.io.File;
import java.util.concurrent.TimeUnit;
public class Flipkart_Test {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
String appUrl = "http://flipkart.com";
driver.get(appUrl);
String expectedTitle = "Online Shopping India Mobile, Cameras, Lifestyle & more Online @ Flipkart.com";
String actualTitle = driver.getTitle();
System.out.println(driver.getTitle());
// compare the expected title of the page with the actual title of the page and print the result
if (expectedTitle.equals(actualTitle))
{
System.out.println("Verification Successful - The correct title is displayed on the web page.");
}
else
{
System.out.println("Verification Failed - An incorrect title is displayed on the web page.");
}
WebElement notificationLink = driver.findElement(By.id("notifications-link"));
notificationLink.click();
}
}
删除
public static void main(String[] args) {
并使用@Test - (Junit( 执行测试