Docker is throwing a NoSuchElementExeption, but everything runs smoothly on localhost

I have developed an automated test using Selenium, and it runs successfully in Eclipse. However, when I try to run it in Docker, I always encounter the NoSuchElement Exception. I am hoping that someone can assist me with this issue. Here is a snippet of my code:

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 function:

public static void login() throws InterruptedException {
    // ---Login LogTicks---
    jse6 = (JavascriptExecutor) driver;
    System.out.println("Logging in 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 logged in successfully");
}

However, I consistently get the following error message:

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)
...
Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.id: userid
...

Despite implementing a waiter as indicated in the exception message, the issue persists.

I would greatly appreciate any assistance! Thank you.

Answer №1

The following error message has been encountered...

tests_1     | Build information: version: 'unknown', revision: 'unknown', time: 'unknown'
tests_1     | System information: 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 information: driver.version: unknown

This indicates that the ChromeDriver experienced difficulty in communicating with the Browsing Context, specifically the Chrome Browser session.


According to the error trace logs, the usage of java.version: '10.0.2' is not yet fully supported. More insights can be found in this discussion thread: Does Selenium v3.141 support Java 13?

Nevertheless,

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

suggests that ChromeDriver is unable to detect the Selenium client version. Additionally,

Driver information: driver.version: unknown

indicates that ChromeDriver is not being acknowledged.

Therefore, there exists a discrepancy between the Selenium Client, ChromeDriver, and the Chrome Browser.


Resolution

To rectify this issue:

  • Upgrade your JDK to the latest version availableJDK 8u251.
  • Update your Selenium to the current versionVersion 3.141.59.
  • Ensure your ChromeDriver is updated to the most recent ChromeDriver v83.0.
  • Make sure your Chrome is at the latest version (Chrome Version 83.0). Refer to ChromeDriver v83.0 release notes.
  • If your base Web Client version is outdated, uninstall and install a newer version.
  • Clean your Project Workspace within your IDE and rebuild with necessary dependencies only.
  • If your base Web Client version is outdated, uninstall and install a recent GA released version.
  • Perform a System Reboot.
  • Execute your @Test as a non-root user.
  • Always call driver.quit() in the tearDown(){} method to gracefully close and destroy WebDriver and Web Client instances.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I extract information exclusively from child nodes with Jsoup?

Currently, I am facing an issue with extracting first-level <li> elements from a <ul> element. Even though I attempt to retrieve only the first-level <li> elements using Jsoup selector or getElementsByTag, the nested <li> elements w ...

When using Java Selenium, the function driver.getDevTools() is not available for the ChromeDriver class

Can anyone help me figure out why I am encountering the error message: "getDevTools() is undefined for the type ChromeDriver"? I am trying to conduct network testing in the Chrome browser. import org.junit.Before; import org.junit.Test; import org.openqa ...

Locate the specified element on the webpage by utilizing Selenium

I've been using Selenium in VBA to navigate to this particular page and I'm trying to click on the 'WIP Management' Button. However, the code I have keeps saying that the element cannot be found. Any assistance would be greatly apprecia ...

Using Python to log into Gmail while also detecting unsuccessful login attempts

While I know that many others have inquired about this before, my specific question is how to log into Gmail (or a Google account) using Python. Currently, I have a code snippet (shown below) that successfully logs the user into Gmail using Selenium. Howev ...

TestNG: A versatile test suite for reliable cross-browser testing

I have a requirement to run all my test cases in a single browser using testng and maven for execution. I have successfully implemented @BeforeSuite and @AfterSuite, but encountered an issue when trying to add a parameter "browser" to my testng.xml file th ...

"Discovering the Selenium version using the webdriver: A step-by-step

Looking to determine the specific version of Selenium that the webdriver is communicating with. I recall using getEval and Selenium.version in the past, but unable to locate how to do it now. Any suggestions on how to accomplish this? ...

Understanding the Contrasts of @By and @FindBy in Page Object Model with Selenium

Seeking assistance to understand the distinction between @By and @Findby when implementing Selenium with Page Object Model. Can anyone shed some light on this? ...

Horizontal Scrolling with C# Selenium in Web Automation

After transitioning from Java to C#, I am attempting to horizontally scroll a webpage using JavaScript, but have been unsuccessful. I also attempted to use the Actions class, but encountered the same issue. Here is the code I tried: IJavaScriptExecutor ...

Unable to Configure SOCKS Proxy with Firefox Webdriver

I am facing an issue with setting up a SOCKS5 proxy in Java using the Firefox driver. final FirefoxOptions FIREFOX_OPTIONS = new FirefoxOptions(); final Proxy PROXY = new Proxy().setProxyType(Proxy.ProxyType.MANUAL).setSocksVersion(5).setSocksProx ...

What is the process for saving a link in a .txt file?

try { const links = document.querySelectorAll('.s-item__wrapper.clearfix .s-item__link'); let linkArray = []; for (let link of links) { linkArray.push(link.getAttribute('href')); } const txtFileContent = link ...

Exploring ways to programmatically click on a button located beneath a text using the Selenium library in Python

I am interested in creating a bot that can automatically like comments on a web page. Each comment has a like and dislike button attached to it. The xPath for the comment is: //*[@id="commentText-40538697"]/span The xPath for the like button is: //*[@id ...

Exception being raised despite handling in JQuery AJAX post request

I am facing an issue with my login JSON service that handles username and password. When I make a call using JQuery 1.10.1 AJAX and input the correct credentials, it functions correctly. However, if I input incorrect credentials, the error function handler ...

Cookie version 68 and below is no longer supported in Chrome

Currently, I am conducting tests on a React application that utilizes an Nginx and Express backend with cookie-based authentication. While testing on older browsers through services like BrowserStack and LambdaTest, I encountered a peculiar issue with cook ...

Tips for extracting specific sub-sections of HTML content with Jsoup

Attempting to extract prices from an HTML file using Jsoup. The structured HTML looks like this: //some html <div class="price-point-wrap use-roundtrippricing"> <div class="price-point-wrap-top use-roundtrippricing"> <div class=" ...

The performance of Selenium on Edge Browser is sluggish

I am currently utilizing Selenium 3.0.0 with Java, operating on a Windows 10 machine OS build - 10586.753. My task involves automating my website on the Edge browser, but I am encountering significant delays. Here is the code snippet for my Edge browser ...

Having trouble deleting browser cookies and session data using Selenium

For my testing in the mobile environment using Java Selenium WebDriver with Appium on Emulator (Genymotion) or physical Android devices, I rely on chromedriver to test a web app in Chrome browser. To prepare for running multiple sets of data, I need to c ...

Having difficulty choosing an item from a concealed dropdown menu with Selenium WebDriver

I've been working with some VBA code and I have the following snippet: Could someone help me figure out how to trigger this element by attaching screenshots or a detailed explanation? driver.FindElementByXPath(".//*[@id='s2id1']/a/span").C ...

Selenium test failed due to an error with an exit code of 255

Currently, I am developing a Selenium test case that utilizes the chromedriver along with mocha. Here is an excerpt from my package.json file: "chromedriver": "^2.46.0", "mocha": "^5.2.0", "selenium-standalone": "^6.16.0", "selenium-webdriver": "^4.0.0-al ...

Waiting for WebDriver to load an element using implicitlyWait

Is there a way to find out how long it takes for WebDriver to click on an element using implicitlyWait in WebDriver (in Java)? For example: Imagine I start the WebDriver with an implicitlyWait value of 30 seconds. Then, when I call webElement.click(); T ...

Unable to select the element transitioning from [display:none] to [display:block] in the bootstrap datetimepicker

I'm facing an issue with a bootstrap DateTime picker on my page. The calendar icon allows me to show the popup, which changes from display: none; to display: block; However, when I click the button labeled 今日, I encounter an error: selenium.comm ...