I'm learning how to use selenium by using java. I got a problem. Having html code:
<h2 class="cart-popup-product__title">Laptop Dell XPS 13 2015 13.3inch Touch (Xám) - Hàng nhập khẩu</h2>
And this is my code to get text:
By productName = By.className("cart-popup-product__title");
public String ProductName(){
String pn = driver.findElement(productName).getText();
return pn;
}
Eclipse display error message: NullPointerException
. I have tried to use xpath
, cssSelector
but it's not working.
*Update: I've solved my problem. I just add this.driver = driver;
to constructor. I forgot to add when initialize constructor.
Thanks all for helping me improve.