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