selenium webdriver findelement error as Exception in thread "main" java.lang.NoSuchMethodError

2k views Asked by At

I am not able to make findElement method to work in the latest WebDriver (v2.52). Have imported all the required classes. Here is the error I'm receiving -

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)

Code that I'm running is -

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

There are 1 answers

7
Roberto Pegoraro On

Remove

public static void main(String[] args) {

And use @Test - (Junit) to execute the test