0

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();
   }
          }
Python Basketball
  • 2,320
  • 3
  • 24
  • 47
Neel
  • 1
  • 3

1 Answers1

0

Remove

public static void main(String[] args) {

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

Roberto Pegoraro
  • 1,313
  • 2
  • 16
  • 31
  • I am not aware of JUnit as of now! But the code above should work, but it's not! Have I missed any imports of classes/interfaces? If not then where can be the issue? – Neel Feb 18 '16 at 05:12
  • from what I saw, it is missing from the package on the first line, something like: - package test; - the first line of the class – Roberto Pegoraro Feb 18 '16 at 10:30
  • @ Roberto - Now that's also not helping! Just tried, got the same result! The issue is only with the _findElement_ method. Other methods are working just fine. If you can just copy-paste it, try to run the code once and if it runs fine for u, then it must be some syncing problem of my system, jar files and the code! Then I gotta call for a doctor! – Neel Feb 18 '16 at 14:55
  • Make sure you are using the latest version of webdriver selenium, because to me, your code is working. – Roberto Pegoraro Feb 18 '16 at 15:31
  • @ Roberto - Thanks! That is the thing! Code is fine! Something else is bothering it to run! I'm having the latest version of webdriver i.e. v2.52! – Neel Feb 18 '16 at 15:47
  • can be error in your project structure. publish it so that we can evaluate – Roberto Pegoraro Feb 18 '16 at 17:10
  • It just worked over the weekend! I cleaned up all the existing projects and again builed up! It worked! Thanks everyone! – Neel Feb 22 '16 at 05:26