From fcb4a33e3a15611925ea547697f29a792310286d Mon Sep 17 00:00:00 2001 From: Sandeep4odesk Date: Sat, 29 Oct 2016 15:09:24 +0530 Subject: [PATCH] Updating the Selenium version (#779) --- selenium-junit-testng/pom.xml | 2 +- .../java/com/baeldung/selenium/SeleniumExample.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/selenium-junit-testng/pom.xml b/selenium-junit-testng/pom.xml index 861c0b1986..cc96ea8529 100644 --- a/selenium-junit-testng/pom.xml +++ b/selenium-junit-testng/pom.xml @@ -53,7 +53,7 @@ org.seleniumhq.selenium selenium-java - 2.53.1 + 3.0.1 junit diff --git a/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java b/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java index ce60a1f638..58d47c0162 100644 --- a/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java +++ b/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java @@ -15,6 +15,7 @@ public class SeleniumExample { private String url = "http://www.baeldung.com/"; public SeleniumExample() { + System.setProperty("webdriver.firefox.marionette", "C:\\selenium\\geckodriver.exe"); webDriver = new FirefoxDriver(); webDriver.manage().window().maximize(); webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); @@ -29,16 +30,20 @@ public class SeleniumExample { return webDriver.getTitle(); } - public void getAboutBaeldungPage() throws Exception { + public void getAboutBaeldungPage() { closeOverlay(); clickAboutLink(); clickAboutUsLink(); } - private void closeOverlay() throws Exception { + private void closeOverlay() { List webElementList = webDriver.findElements(By.tagName("a")); - if (webElementList != null && !webElementList.isEmpty() && webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().isPresent()) { - webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().orElseThrow(NoSuchElementException::new).click(); + try { + if (webElementList != null && !webElementList.isEmpty()) { + webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().orElseThrow(NoSuchElementException::new).click(); + } + } catch (NoSuchElementException exception) { + exception.printStackTrace(); } }