I was launching https://www.americangolf.co.uk/ website and clicking on cart. but despite having thre correct xpath, cart is not getting clicked and i am getting an exception.
Code:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Cnn {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://www.americangolf.co.uk/");
driver.findElement(By.xpath("//*[@id=\"header-top-wrapper\"]/div/div[3]/div[2]/div[4]/div/div[2]/a/i")).click();
String text = driver.findElement(By.xpath("//*[@id=\"cart\"]/h1")).getText();
System.out.println(text);
driver.quit();
}
}
Instructor
Ashish Thakur Replied on 29/07/2019
Please share the complete exception stack trace. We won't be able to suggest a solution without that.