1

i have programmed a test automation in selenium, which also works when i run it in eclipse. I want to run it in Docker but there I always face the Expetion NoSuchElement. I really hope someone can help me. So here is what I did:

final static String websiteUnderTest = "https://test.com";

final static String remoteWebDriverUrl = "http://selenium:4444/wd/hub";

//       Docker Browser setting
        Capabilities chromeCapabilities = new ChromeOptions();
        ((ChromeOptions) chromeCapabilities).addArguments("--headless");
        driver = new RemoteWebDriver(new URL(remoteWebDriverUrl), chromeCapabilities);

    driver.get(websiteUnderTest);
        wait = new WebDriverWait(driver, 30);
        login();

The login:

public static void login() throws InterruptedException {
        // ---Login LogTicks---
        jse6 = (JavascriptExecutor) driver;
        System.out.println("Login User");
        
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("userid")));
    
        WebElement userID = driver.findElement(By.id("userid"));
        jse6.executeScript("window.scrollTo(0,"+userID.getLocation().y+")");
        userID.click();
        userID.sendKeys("PID6D1F");
        driver.findElement(By.id("next-btn")).click();
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("password")));
        WebElement password = driver.findElement(By.id("password"));
        password.sendKeys("LogTicksPool-ID");
        driver.findElement(By.id("loginSubmitButton")).click();

        System.out.println("User PID6D1F has login");
    }

I always get that:

tests_1     | Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.id: userid (tried for 30 second(s) with 500 milliseconds interval)
tests_1     |   at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:113)
tests_1     |   at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:283)
tests_1     |   at SeleniumTests.login(SeleniumTests.java:99)
tests_1     |   at SeleniumTests.main(SeleniumTests.java:49)
tests_1     | Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.id: userid
tests_1     | For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
tests_1     | Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
tests_1     | System info: host: '390560c4caf4', ip: '172.18.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '4.19.76-linuxkit', java.version: '10.0.2'
tests_1     | Driver info: driver.version: unknown
tests_1     |   at org.openqa.selenium.support.ui.ExpectedConditions.lambda$findElement$0(ExpectedConditions.java:896)
tests_1     |   at java.base/java.util.Optional.orElseThrow(Optional.java:397)
tests_1     |   at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
tests_1     |   at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:44)
tests_1     |   at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:206)
tests_1     |   at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:202)
tests_1     |   at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:260)
tests_1     |   ... 2 more

And as you can see in the exeption I already have a waiter.

I am greatfull for every help! Thank you

sunxca
  • 85
  • 1
  • 1
  • 6
  • I have no exp with docker or selenium, but does't this local path `"C:\\Users\\calisay\\eclipse-workspace\\LogTicks-Testautomatisierung\\driver\\chromedriver.exe"` makes it only run in your machine? – Henrique Sabino Jun 10 '20 at 11:39
  • 1
    Yes I only use that path when I run it local in Eclipse. The second part of my Code with the comment "Docker Browser setting" is what I use when i want to run it in Docker. – sunxca Jun 10 '20 at 11:55
  • Having the exact same issue - everything works in localhost but not in Docker - did you ever figure out why? @sunxca – umop apisdn Sep 26 '21 at 09:07

1 Answers1

1

This error message...

tests_1     | Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
tests_1     | System info: host: '390560c4caf4', ip: '172.18.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '4.19.76-linuxkit', java.version: '10.0.2'
tests_1     | Driver info: driver.version: unknown

...implies that the ChromeDriver was unable to communicate with the Browsing Context i.e. Chrome Browser session.


As per the error trace logs, you are using java.version: '10.0.2' which is still not fully supported. You can find a relevant discussion in Does Selenium v3.141 support Java 13?

However,

Build info: version: 'unknown', revision: 'unknown', time: 'unknown'

implies ChromeDriver is unable to recognise Selenium client version. Moreover,

Driver info: driver.version: unknown

implies ChromeDriver isn't recognized back.

So there is a clear mismatch between Selenium Client , ChromeDriver and the Chrome Browser


Solution

Ensure that:

  • JDK is upgraded to current levels JDK 8u251.
  • Selenium is upgraded to current levels Version 3.141.59.
  • ChromeDriver is updated to current ChromeDriver v83.0 level.
  • Chrome is updated to current Chrome Version 83.0 level. (as per ChromeDriver v83.0 release notes)
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352