Hello sir
I was trying to solve the problem given in video 13 but it is not working. Please tell where I am wrong?
driver.get("https://www.americangolf.co.uk/");
driver.findElement(By.xpath("//a[contains(@title='View shopping cart')]")).click();
Thanks & Regards
Parveen
Instructor
Ashish Thakur Replied on 09/04/2019
You need to make sure that the element is visible on the screen before clicking
you need to add the action class before clicking to view View shopping cart link.
driver.get("https://www.americangolf.co.uk/");
WebElement element=driver.findElement(By.xpath("//div[@class='header-minicart minicart']'));
Actions act=new Actions(driver);
act.moveElementTo(element).build().perform().
driver.findElement(By.xpath("//a[contains(@title='View shopping cart')]")).click();
check if it working,it is worked from my end.
Instructor
Ashish Thakur Replied on 10/04/2019
Try the code provided by Avinash.
first of all thanks to all.
Sir it is not working. I have tired but it is not working.
import java.util.concurrent.TimeUnit;
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.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
public class americangolf {
public static void main(String[] args) throws InterruptedException {
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
options.addArguments("disable-infobars");
System.setProperty("webdriver.chrome.driver","C://Users//abc//Desktop//Core java notes//Crome Driver//chromedriver.exe");
WebDriver driver=new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(2000,TimeUnit.SECONDS);
driver.manage().deleteAllCookies();
driver.get("https://www.americangolf.co.uk/");
System.out.println("I am after get");
WebElement element=driver.findElement(By.xpath("//div[@class='header-minicart minicart']"));
Actions act=new Actions(driver);
act.moveToElement(element).perform();
driver.findElement(By.xpath("//a[contains(@title,'View shopping cart')]")).click();
System.out.println("I am in the end ");
}
}
"//a[contains(@title,'View shopping cart')]" is the address of two locators.so that it is not working.
see the below code.it is working.
driver.get("https://www.americangolf.co.uk/");
System.out.println("I am after get");
WebElement element=driver.findElement(By.xpath("//*[@id='header-navigation']/div[2]/div[4]/div/div[2]/a/i"));
element.click();
System.out.println("Click to basket");
System.out.println("I am in the end ");