The following is the snippet of WebDriver code using Java:
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.pl/");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement element = driver.findElement(By.name("q"));
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement query = driver.findElement(By.xpath("//html/body/div[2]/span/center/form/table/tbody/tr/td[2]/div/div/input"));
query.sendKeys("asd");
After execution of code I got the following exception:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//html/body/div[2]/span/center/form/table/tbody/tr/td[2]/div/div/input"} System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_24' Driver info: driver.version: RemoteWebDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:131) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:105) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:409) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:192) at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:265) at org.openqa.selenium.By$6.findElement(By.java:205) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:184) at test.main(test.java:24)
What's the wrong in my code?