Xpath in Selenium Xpath in Selenium selenium selenium

Xpath in Selenium


I think it was your xpath which was causing the problem also your element was not on the view to be clickable

This below code is tested and worked for me

import java.util.concurrent.TimeUnit;import org.openqa.selenium.By;import org.openqa.selenium.JavascriptExecutor;import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.firefox.FirefoxDriver;import org.testng.annotations.Test;public class test1 {@Testpublic void chec() throws InterruptedException{    System.setProperty("webdriver.chrome.driver","C://Temp//imp//chromedriver.exe");    WebDriver d = new ChromeDriver();    d.manage().timeouts().implicitlyWait(40,TimeUnit.SECONDS);    d.get("http://au.support.tomtom.com/");    d.manage().window().maximize();    JavascriptExecutor jse = (JavascriptExecutor)d;     d.findElement(By.xpath(".//*[@id='rn_PageFooter_16']/footer/div[3]/button")).click();    Thread.sleep(5000);    jse.executeScript("scroll(0, -250);");    d.findElement(By.xpath("html/body/div[4]/div/div[2]/footer/div[2]/div/div/div/div[1]/div/div[1]/div/div[2]/ul/li[1]/a")).click();}}


Why use XPath? It's much easier to find the Australia flag using CSS selector:

li .tt-flag-image.australia

Full code:

driver.findElement(By.cssSelector("li .tt-flag-image.australia")).click();