2

I run my automation (cucumber, junit, selenium chrome web-driver).

when I run locally, the test passes.

But when I'm using remote-web-driver to run on another machine,

I usually (not always), get this error while trying to get the src of an image:

 Then banner image in preview html should be "p_1047_o_9075_banner_1423040308.png"
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
  (Session info: chrome=41.0.2272.118)
  (Driver info: chromedriver=2.13.307650 (feffe1dd547ee7b5c16d38784cd0cd679dfd7850),platform=Mac OS X 10.9.5 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'rond-macpro.roam.corp.google.com', ip: '172.16.188.22', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.8.0_40'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/var/folders/00/1lc48000h01000cxqpysvccm006dhj/T/.org.chromium.Chromium.ofRqKa}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=41.0.2272.118, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 1213beaa792477d6510f7c18cad58284
Command duration or timeout: 395 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
System info: host: 'w.com', ip: '172.28.144.7', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-30-generic', java.version: '1.8.0_25'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/var/folders/00/1lc48000h01000cxqpysvccm006dhj/T/.org.chromium.Chromium.ofRqKa}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=41.0.2272.118, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, webdriver.remote.sessionid=bdc90e5b-c05a-4685-b5fa-5a7c4b65347c, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: bdc90e5b-c05a-4685-b5fa-5a7c4b65347c

this is different than other cases when the waitDriver just finds a different image name and then I get:

Then banner image in preview html should be "p_1047_o_9075_banner_1423040308.png"
org.openqa.selenium.TimeoutException: Timed out after 5 seconds waiting for w.testing.web.utils.WebExtensions$$Lambda$3/925829785@5c1b89ac
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40'
System info: host: 'w.com', ip: '172.28.144.7', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-30-generic', java.version: '1.8.0_25'
Driver info: org.openqa.selenium.remote.RemoteWebDriver

here is my code to verify an image src:

webExtensions.waitForSrc
                (getSelectorForImageElement(ImageElements.BANNER), BANNER_IMAGE_BASE_PATH + expectedImageName);

    public void waitForSrc(By by, String expectedImageName) {
        waitForCondition(input ->
        {
            try {
                WebElement webElement = input.findElement(by);
                if (webElement == null) {
                    return false;
                } else {
                    String currentSrc = webElement.getAttribute("src");
                    System.out.println(currentSrc);
                    return currentSrc.contains(expectedImageName);
                }
            } catch (TimeoutException exception) {
                exception.printStackTrace();
                //java.util.logging.
                return false;
            }

        });
    }

 public void waitForCondition(Predicate<WebDriver> condition) throws TimeoutException {
        WebDriverWait driverWait = new WebDriverWait(driver, 5);
        driverWait.until(condition);
    }
Elad Benda2
  • 13,852
  • 29
  • 82
  • 157
  • Have a look manually...what happens when you load that page? Specifically does the DOM get changed *in any way* as the image is downloaded? – Arran Apr 10 '15 at 22:30
  • the problem is that it runs locally OK, the problem happens only when I run remoetly, and then when I stop and debug i see the image OK – Elad Benda2 Apr 11 '15 at 09:44

1 Answers1

0

This issue can be dealt with in several ways. In this topic are some good suggestions: Selenium WebDriver How to Resolve Stale Element Reference Exception?

Community
  • 1
  • 1
FDM
  • 628
  • 6
  • 18