1

I could use some advice on a specific Selenium script error. Some context: I'm trying to verify an former colleague's old script is still workable. Unfortunately that colleague is no longer around to ask, so I'm having to do a lot of guess work.

His script is a simple demo script (in Java) that's supposed to go WhatsApp web and verify that the scan code displayed there is regularly refreshing. Here's the script:

import java.util.function.Supplier;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.junit.Assert;
import org.junit.jupiter.api.Test;

public class WhatsAppTest {
    @Test
    public void testScanCodeRenew() throws InterruptedException {
        
        System.setProperty("webdriver.gecko.driver","D:\\WebDriver\\geckodriver.exe");
        
        WebDriver driver=new FirefoxDriver();
        
        driver.get("https://web.whatsapp.com/");
        
        By xpath = By.xpath("//div[contains(@class,'_2EZ_m')]");
        WebElement scanCode = new WebDriverWait(driver, 10)
            .until(ExpectedConditions.presenceOfElementLocated(xpath));
        
        Supplier<String> getScanCode = 
               () -> scanCode.getAttribute("data-ref");
        
        String oldCode = getScanCode.get();
                
        for(int index = 0 ; index < 3 ; index++) {
            
            Thread.sleep(30_000);
            
            String newCode = getScanCode.get();
            
            Assert.assertNotEquals(oldCode, newCode);
            
            oldCode = newCode;
        }
    }

}

When I attempt to run this script in Eclipse, it fails with this error:

JavaScript warning: https://web.whatsapp.com/app.91e887b2b63434f2a2e6.js, line 1: unreachable code after return statement

My layman's guess (I'm by no means a scripting expert) is the error is being thrown by the site's own JavaScript, not the Selenium script, but I may be completely misinterpreting that. Here's the full error output seen in the Eclipse console:

1605553468566   geckodriver INFO    Listening on 127.0.0.1:15630
1605553469174   mozrunner::runner   INFO    Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "--marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\doubl\\AppData\\Local\\Temp\\rust_mozprofilehOBapN"
Can't find symbol 'eglSwapBuffersWithDamageEXT'.
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
1605553472011   Marionette  INFO    Listening on port 51076
1605553472311   Marionette  WARN    TLS certificate errors will be ignored for this session
Nov 16, 2020 1:04:32 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
JavaScript warning: https://web.whatsapp.com/app.91e887b2b63434f2a2e6.js, line 1: unreachable code after return statement
JavaScript warning: https://web.whatsapp.com/app.91e887b2b63434f2a2e6.js, line 1: unreachable code after return statement

Might this script be salvagable, or have I hit a brick wall?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
James Panetti
  • 238
  • 1
  • 2
  • 13
  • that error wouldn't be a problem... more of a warning really. If the test failed, wouldn't that be the assert? Debug oldCode / newCode. – pcalkins Nov 17 '20 at 19:05
  • that lambda is really odd... but I'd try/catch this line: String newCode = getScanCode.get(); I'd expect a stale element exception if the DOM updates at all. – pcalkins Nov 17 '20 at 19:11

1 Answers1

1

To start with Idon't see any tangible error within the logs. The concerned logs:

JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
.
JavaScript warning: https://web.whatsapp.com/app.91e887b2b63434f2a2e6.js, line 1: unreachable code after return statement
JavaScript warning: https://web.whatsapp.com/app.91e887b2b63434f2a2e6.js, line 1: unreachable code after return statement

...implies that there was a JavaScript error while GeckoDriver initiated/spawned a new Browsing Context i.e. Firefox browsing session.


When Selenium driven GeckoDriver initiates a Browsing Context there can be a couple of JavaScript related WARNINGS and ERRORS within the TRACE level logs during initialization. You can safely ignore those initialization errors till GeckoDriver is successfully able to initiate a Firefox Browsing session.


Conclusion

When the createSession is successful and W3C dialect is detected you can safely ignore the errors.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Ah, that makes sense, thank you! So where this confused me is that in Eclipse, execution terminates right after that message appears in the console. Firefox indeed successfully opens and navigates to the web page in question, but my understanding of the original author's code is that it's supposed to check for a refresh in 30 seconds, but this terminates long before then. – James Panetti Nov 20 '20 at 20:24