Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • An element could not be located on the page using the given search parameters

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 8.93k
    Comment on it

    I tried to run the below code

    public class TestSelendroidApp {
    public static AndroidDriver driver;
        public static void main(String[] args) throws MalformedURLException, InterruptedException {
             File app = new File("E:\software\selendroid-test-app-0.11.0.apk");
             DesiredCapabilities capabilities = new DesiredCapabilities();
             DesiredCapabilities cap = new DesiredCapabilities();
             cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
             capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
             capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
             capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.2.2");
             capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
             capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
             driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
                 driver.findElementByAndroidUIAutomator("UiSelector().className(\"android.widget.CheckBox\").checked(false)").click();
                 driver.quit();
                }
    }
    

    After running this code I am getting the following error:

    Exception in thread "main" org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 565 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33' System info: host: 'xxxxxxxxxxxxx', ip: 'xxxxxxxxxxxxxxxxxx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0' Driver info: io.appium.java_client.android.AndroidDriver Capabilities [{app=E:\software\selendroid-test-app-0.11.0.apk, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=42033d5fcacf4100, platform=LINUX, desired={app=E:\software\selendroid-test-app-0.11.0.apk, platformVersion=4.2.2, automationName=Appium, platformName=Android, deviceName=Android}, platformVersion=4.2.2, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, browserName=Android, takesScreenshot=true, javascriptEnabled=true, platformName=Android}] Session ID: 72adde8a-db33-4f2b-a26e-90f1640cb7c4 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:408) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:176) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352) at io.appium.java_client.android.AndroidDriver.findElementByAndroidUIAutomator(AndroidDriver.java:264) at TestSelendroidApp.main(TestSelendroidApp.java:58)

    Solution for the above error is:

    The above error comes when the condition is false and the element could not be located with the given search criteria but still we are trying to perform some action over the webelement. For eg: in the above highlighted line of code, we are trying to click the checkbox which is not checked(ie trying to click the unchecked checkbox) but the checkbox is in checked state, so the unchecked checkbox could not be located and we got the above error. In the above code if we pass ''true' as an argument in checked() method then the webbelement could be located.

    driver.findElementByAndroidUIAutomator("UiSelector().className(\"android.widget.CheckBox\").checked(true)").click();

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: