Skip to content

Commit 5cff73c

Browse files
skabashnyukmaxandersen
authored andcommitted
Webdriver example enhancements
Added slf4j-simple. Used to have better output from WebDriverManager. Added webdriver implicitlyWait 10 sec. Used to make sure that html elements rendered in time and avoid nosuchelementexception. See https://stackoverflow.com/questions/47337738/exception-in-thread-main-org-openqa-selenium-nosuchelementexception-no-such-e.
1 parent e3c45af commit 5cff73c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

examples/webdriver.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//usr/bin/env jbang "$0" "$@" ; exit $?
22
//DEPS io.github.bonigarcia:webdrivermanager:3.8.1
33
//DEPS org.seleniumhq.selenium:selenium-java:3.141.59
4+
//DEPS org.slf4j:slf4j-simple:1.7.30
45

56
import static java.awt.Toolkit.getDefaultToolkit;
67
import static javax.imageio.ImageIO.write;
@@ -9,6 +10,7 @@
910
import java.awt.Robot;
1011
import java.awt.image.BufferedImage;
1112
import java.io.File;
13+
import java.util.concurrent.TimeUnit;
1214

1315
import org.openqa.selenium.*;
1416
import org.openqa.selenium.chrome.*;
@@ -27,8 +29,10 @@ public static WebDriver setupDriver() {
2729
options.addArguments("--disable-dev-shm-usage");
2830
options.addArguments("--disable-browser-side-navigation");
2931
options.addArguments("--disable-gpu");
30-
options.setPageLoadStrategy(PageLoadStrategy.NONE);
31-
return new ChromeDriver(options);
32+
options.setPageLoadStrategy(PageLoadStrategy.NONE);
33+
WebDriver driver = new ChromeDriver(options);
34+
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
35+
return driver;
3236
}
3337

3438
public static void takeScreenShot() throws Exception {

0 commit comments

Comments
 (0)