0

Hi I am using selendroid to test my app but I am getting an error in that the element id is not found, and the id displayed in error is not passed by me anywhere in my code.

Following is the trace of TestNG log:

org.openqa.selenium.StaleElementReferenceException: The element with id '749f7f36-cf23-cf8a-3ba4-089302016ab6' was not found. Command duration or timeout: 23 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'admin-PC', ip: '172.25.14.100', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_21' Session ID: 75f030b7-cad7-9f00-452d-b29017e502cb Driver info: io.selendroid.SelendroidDriver Capabilities [{automationName=selendroid, platform=ANY, platformName=android, browserName=selendroid, emulator=false, aut=in.myapp:2.3}] 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:204) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268) at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:79) at com.selendroid.test.SelendroidTest.bRechargePrepaid(SelendroidTest.java:116) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85) at org.testng.internal.Invoker.invokeMethod(Invoker.java:648) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:834) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1142) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108) at org.testng.TestRunner.privateRun(TestRunner.java:771) at org.testng.TestRunner.run(TestRunner.java:621) at org.testng.SuiteRunner.runTest(SuiteRunner.java:357) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310) at org.testng.SuiteRunner.run(SuiteRunner.java:259) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1176) at org.testng.TestNG.runSuitesLocally(TestNG.java:1101) at org.testng.TestNG.run(TestNG.java:1009) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) Caused by: io.selendroid.server.common.exceptions.StaleElementReferenceException: The element with id '749f7f36-cf23-cf8a-3ba4-089302016ab6' was not found.

I am adding code for the driver and test exception is happening at recharge_btn id

private SelendroidDriver driver;
    @BeforeClass
        public void setUp() throws Exception {
            SelendroidConfiguration config = new SelendroidConfiguration();
            config.addSupportedApp("myapp.apk");
    //      SelendroidLauncher selendroidServer = new SelendroidLauncher(config);
    //      selendroidServer.launchSelendroid();
            capa = new SelendroidCapabilities("in.myapp:2.3");
            // capa.setAut("io.selendroid.testapp:0.15.0");
            // capa.setPlatformVersion(DeviceTargetPlatform.ANDROID19);
            capa.setEmulator(false);
            driver = new SelendroidDriver(capa);
        }
@Test
    public void bRechargePrepaid() throws Exception {
//      driver = new SelendroidDriver(capa);
        System.out.println("Starting Prepaid Recharge");
        driver.get(PREPAID_RECHARGE_ACTIVITY);
        // WebElement rechargeList = driver.findElement(By.linkText("Prepaid"));
        // rechargeList.click();

//      File file = new File("D:/prepaidRecharge.txt");
//      fr = new FileReader(file);
//      br = new BufferedReader(fr);
//      String fileLine = "";
//      try {
//          while ((fileLine = br.readLine()) != null) {

                WebElement element = driver.findElement(By
                        .id("mobile_number_edit"));
                element.sendKeys("9780325188");
                element = driver.findElement(By.id("amount_edit"));
                element.clear();
                element.sendKeys("100");
                element = driver.findElement(By.id("edt_operator"));
                element.click();
                element = driver
                        .findElement(By.linkText("VODAFONE"));
                element.click();
                Thread.sleep(2000);
                element = driver.findElement(By.id("recharge_btn"));
                element.click();
                element = driver.findElement(By.id("button1"));
                element.click();
                Thread.sleep(15000);
                driver.navigate().back();

//          }
//      } finally {
//          br.close();
//          fr.close();
//      }

        Thread.sleep(10000);

    }
Sandeep Singh
  • 745
  • 4
  • 20
  • can you please share your web driver code you have written? – Helping Hands Jul 03 '15 at 06:13
  • Seems like an issue of an stale element. Could you try putting a sleep before trying to find that element. The problem might be that the element is deleted entirely or the element is no longer attached to the dom. In some edge cases the element changes, but the keeps the same locator semantic. – Madis Kangro Jul 03 '15 at 06:32
  • i have added the code . and i did put sleep before the element that was causing the problem, but still getting the same error. – Sandeep Singh Jul 03 '15 at 06:50
  • It worked. I put in sleep after almost every click and it worked. Thanks @MadisKangro. – Sandeep Singh Jul 03 '15 at 06:58
  • Try giving Implicit Wait instead of sleep. – Manu Jul 03 '15 at 07:44
  • Yeah do an implicit wait or to an for cycle where it tries to find the element a couple of times while catching the stale element exception. Thread.sleep usually isn't nice, but I used it also in some cases. – Madis Kangro Jul 03 '15 at 07:46
  • Thanks for the suggestion, will implement implicit sleep. – Sandeep Singh Jul 03 '15 at 07:52

0 Answers0