Selenide opens IE but can't select element by ID

1

we are just starting with selenide frontend tests. I wrote tests for our first workflow using the defaults and everything works just fine (in Chrome).

Now i would like to run the test in the 3 major browser: IE, chrome and firefox.

Again, everything works fine for chrome and firefox. But IE is just getting opened, calls the start url and loads it. Afterwards, the first line of code ist just to select an input-field by ID and set a value. This always crashes and i don't understand why.

here is the code:

public static void loginUser(String userId, String userPassword) {
    open(loginUrl);
    $("#username").setValue(userId); // crashes here
    $("#password").setValue(userPassword);
    $("#loginBtn").click();
    $("#mainNav").should(exist); // Waits until element disappears
}

in a previous version i used $(By.id("username")).setValue(userId); but this did not work as well.

Maybe it is the way i start my tests, so here is some code for configurating the tests

@RunWith(Parameterized.class)
public class MyTest{
    private String browser;
    public MyTest(String browser){
        this.browser = browser;
    }
    @Parameterized.Parameters
    public static Collection<Object[]> data() {
        Object[][] data = {{"ie"}, {"chrome"}, {"firefox"}};
        return Arrays.asList(data);
    }

    private Config myConf = new Config();
    @Before
    public void setUp(){
        myConf.setUp(browser);
    }


    public static void loginUser(String userId, String userPassword) {
        open(loginUrl);
        $("#username").setValue(userId);
        $("#password").setValue(userPassword);
        $("#loginBtn").click();
        $("#mainNav").should(exist); // Waits until element disappears
    }

    @Test
    public void myTest(){
        loginUser(userId, userPassword);
        // some code
    }
}

public class Config {
    public static void setUp(String browser) {
        Configuration.browser = browser;
        Configuration.startMaximized = true;
    }
}

Thanks in advance

Edit: the error message:

Aug 02, 2019 11:14:32 AM com.codeborne.selenide.drivercommands.LazyDriver getAndCheckWebDriver
INFORMATION: No webdriver is bound to current thread: 1 - let's create a new webdriver
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Aug 02, 2019 11:14:32 AM java.util.prefs.WindowsPreferences <init>
WARNUNG: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
Started InternetExplorerDriver server (64-bit)
3.141.0.0
Listening on port 33492
Only local connections are allowed
Aug 02, 2019 11:14:40 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMATION: Detected dialect: W3C
Aug 02, 2019 11:14:40 AM com.codeborne.selenide.webdriver.WebDriverFactory logBrowserVersion
INFORMATION: BrowserName=internet explorer Version=11 Platform=WINDOWS
Aug 02, 2019 11:14:40 AM com.codeborne.selenide.webdriver.WebDriverFactory createWebDriver
INFORMATION: Selenide v. 5.2.4
Aug 02, 2019 11:14:40 AM com.codeborne.selenide.webdriver.WebDriverFactory logSeleniumInfo
INFORMATION: Selenium WebDriver v. 3.14.0 build time: 2018-08-02T20:19:58.91Z
Aug 02, 2019 11:14:40 AM com.codeborne.selenide.drivercommands.CreateDriverCommand createDriver
INFORMATION: Create webdriver in current thread 1: InternetExplorerDriver -> InternetExplorerDriver: internet explorer on WINDOWS (543437e3-a592-4e4a-91e9-fcc55dd1e5ec)
Aug 02, 2019 11:14:44 AM com.codeborne.selenide.impl.ScreenShotLaboratory savePageSourceToFile
WARNUNG: Failed to save page source to 1564737284503.0 because of org.openqa.selenium.NoSuchWindowException: Unable to get browser
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'LAPTOP-UF8SMQ23', ip: '192.168.109.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:33492/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 543437e3-a592-4e4a-91e9-fcc55dd1e5ec
Aug 02, 2019 11:14:44 AM com.codeborne.selenide.impl.ScreenShotLaboratory takeScreenshotImage
SCHWERWIEGEND: Failed to take screenshot to 1564737284503.0 because of org.openqa.selenium.NoSuchWindowException: Unable to get browser
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'LAPTOP-UF8SMQ23', ip: '192.168.109.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:33492/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 543437e3-a592-4e4a-91e9-fcc55dd1e5ec

Element not found {#username}
Expected: visible or transparent

Page source: file:/C:/Users/Pascal/Dev2/selfservice-test/build/reports/tests/1564737284503.0.html
Timeout: 4 s.
Caused by: NoSuchWindowException: Currently focused window has been closed.
    at com.codeborne.selenide.impl.WebElementSource.createElementNotFoundError(WebElementSource.java:37)
    at com.codeborne.selenide.impl.ElementFinder.createElementNotFoundError(ElementFinder.java:100)
java
selenium
internet-explorer
selenium-iedriver
selenide
asked on Stack Overflow Aug 2, 2019 by JustAMicrobe • edited Aug 2, 2019 by DebanjanB

1 Answer

1

This error message...

System info: host: 'LAPTOP-UF8SMQ23', ip: '192.168.109.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities {acceptInsecureCerts: false, browserName: internet explorer, browserVersion: 11, javascriptEnabled: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), se:ieOptions: {browserAttachTimeout: 0, elementScrollBehavior: 0, enablePersistentHover: true, ie.browserCommandLineSwitches: , ie.ensureCleanSession: false, ie.fileUploadDialogTimeout: 3000, ie.forceCreateProcessApi: false, ignoreProtectedModeSettings: false, ignoreZoomSetting: false, initialBrowserUrl: http://localhost:33492/, nativeEvents: true, requireWindowFocus: false}, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 543437e3-a592-4e4a-91e9-fcc55dd1e5ec

Element not found {#username}
Expected: visible or transparent
.
Caused by: NoSuchWindowException: Currently focused window has been closed.

...implies that the InternetExplorerDriver was unable to locate the desired element as the element wasn't visible or transparent

Solution

You need to Wait until element exists and you can use the following solution:

public static void loginUser(String userId, String userPassword) {
    open(loginUrl);
    $("#username").should(exist);
    $("#username").setValue(userId);
    $("#password").setValue(userPassword);
    $("#loginBtn").click();
    $("#mainNav").should(exist);
}

Additionally, the java.version: '1.8.0_162' seems to be quite ancient now and you need to upgrade JDK to current levels JDK 8u212.

You can find a detailed discussions in “NoSuchWindowException: no such window: window was already closed” while switching tabs using Selenium and WebDriver through Python3

answered on Stack Overflow Aug 2, 2019 by DebanjanB

User contributions licensed under CC BY-SA 3.0