The command driver.findElement(By.xpath("xpath"). click();
is not working in Web driver. Kindly check the below code written in selenium RC and webdriver.
Selenium RC :
public void courselibrary_click() throws Exception {
selenium.open("/ksdlms/");
//selenium.setSpeed(null);
selenium.windowMaximize();
selenium.windowFocus();
selenium.type("name=userID", "asha");
selenium.type("name=password", "welcome");
selenium.click("id=loginbutton");
//selenium.waitForPageToLoad("30000");
Thread.sleep(30000);
System.out.println("ok");
selenium.click("xpath=html/body/table/tbody/tr/td[2]/table/tbody/tr[2]/td[1]/table/tbody/tr[283]/td[2]/a");
System.out.println("ok ok");
}
Webdriver :
public void courselibrary_click() throws Exception {
driver.get(baseurl);
driver.manage().window().maximize();
//driver.switchTo().window("KESDEE Learning Management System.");
driver.findElement(By.name("userID")).sendKeys("asha");
driver.findElement(By.name("password")).sendKeys("welcome");
driver.findElement(By.id("loginbutton")).click();
System.out.println("ok");
Thread.sleep(3000);
System.out.println("ok ok");
// driver.implicitly_wait(300);
//System.out.println("ok");
**driver.findElement(By.xpath("html/body/table/tbody/tr/td[2]/table/tbody/tr[2]/td[1]/table/tbody/tr[283]/td[2]/a")).click();**
//selenium.click("xpath=html/body/table/tbody/tr/td[2]/table/tbody/tr[2]/td[1]/table/tbody/tr[6]/td[2]/a");
//element.click();
Thread.sleep(1000);
}
After login to the application, driver is unable to find an element and throwing exception:
FAILED: courselibrary_click
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"html/body/table/tbody/tr/td[2]/table/tbody/tr[2]/td[1]/table/tbody/tr[283]/td[2]/a"}
Command duration or timeout: 44 milliseconds