0

I want to pass Selenium webDriver to another class but no success. The program should open the browser ("Google") and type some word in the main class and in the 2nd one should press the "Google" button.

Here is my main class:

public class MainClass {

public WebDriver driver;

@Test
public void main()
{
    System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Selenium\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.get("https://www.google.co.il/");
    driver.findElement(By.name("q")).sendKeys("walla");
}

And here is the class I want to use the driver from the main.

public class FirstClass extends MainClass{

@Test
public void printOnScreen()
{
    driver.findElement(By.name("btnK")).click();
}

When I run it its say to me:

PASSED: main
FAILED: printOnScreen
java.lang.NullPointerException

What I am doing wrong?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – mkrieger1 Mar 11 '21 at 17:34
  • .findElement(By.name("btnK")) <-- This is returning Null to you. It is either By.name("btnK") that is returning null, or findElement() itself :) – JCompetence Mar 11 '21 at 19:58

0 Answers0