title: How to use mockito to mock webdriver?
body: <p>I want to be able to do unit test for my Selenium integration tests and to do that I need to be able to mock the driver and the elements needed for the tests, this is a quick example of a function that returns the name of the element.</p>
  
  <pre><code>public class demo {
  
    private WebDriver mockDriver;
    private WebElement mockElement;
  
    @Before
    public void setUp(){
      this.mockDriver = mock(WebDriver.class);
      this.mockElement = mock(WebElement.class, withSettings().name("elementName"));
      when(this.mockDriver.findElement(By.id("testmock"))).thenReturn(mockElement);
    }
  
    public String getName(String id){
      WebElement testElement = mockDriver.findElement(By.id(id));
      return testElement.getAttribute("name");
    }
  
    @Test
    public void assertElementName() throws InterruptedException {
      Assert.assertTrue(getName("testmock").equals("elementName"));
    }
  }
  </code></pre>
  
  <p>this gives me a <code>java.lang.NullPointerException</code> on the return in <code>getName()</code>.
  I am obviously using this wrong but I can't figure out how. Anyone with some experience in this that could point me in the right direction?</p>