0
votes

I am trying to find the element using selenium locator but getting unable to find element tried with all locators

After trying to find element by all locator i sed selenium IDE and copied xpath from IDE and used but still getting same error message

System.setProperty("IEDriverServer", "C:\\Users\\cc301438\\Downloads\\Browser-Setup\\Drivers\\IEDriverServer_x64_3.14.0\\IEDriverServer.exe");

WebDriver driver=new InternetExplorerDriver();
            driver.get("https://netbank.nedsecure.co.za/Browser/Brands/Nedbank/Logon/Logon.aspx");

        driver.findElement(By.id("ProfileId")).sendKeys("46732258");
        driver.findElement(By.id("PinNo")).sendKeys("8026");
        driver.findElement(By.id("Password")).sendKeys("test123");
        driver.findElement(By.xpath("img[@id='LoginPagelet_LogonID']")).click();

        driver.quit();

Error

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == img[@id='LoginPagelet_LogonID'] (WARNING: The server did not provide any stacktrace information) For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.3.0', revision: 'unknown', time: '2011-08-03 19:22:45' System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151' Driver info: driver.version: RemoteWebDriver at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 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:405) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:193) at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:266) at org.openqa.selenium.By$ByXPath.findElement(By.java:323) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:185) at com.firstTest.SimpleDemo.Login.main(Login.java:33)

1
You should check the syntax of xpath. It should start with '//'. It should be like this - By.xpath("//img[@id='LoginPagelet_LogonID']") - Sureshmani Kalirajan
Thanks above solution is working - user3686241

1 Answers

0
votes

@user3686241, hi. Attaching You PDF with best XPath locator practices below: xpath locators best practices, part 1 xpath locators best practices, part 2

So in Your case correct locator should look : .....

 driver.findElement(By.id("Password")).sendKeys("test123");
 driver.findElement(By.xpath("//img[@id='LoginPagelet_LogonID']")).click();

 driver.quit();

Two // mean - to find all elements on HTML page with img tag and ID attribute being equal to LoginPagelet_LogonID.