Skip to content

Commit 506bfb9

Browse files
author
Grzegorz Piwowarek
committed
closeOverlay refactor
1 parent b74ce59 commit 506bfb9

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

‎selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package main.java.com.baeldung.selenium;
22

3-
import java.util.List;
4-
import java.util.NoSuchElementException;
5-
import java.util.concurrent.TimeUnit;
6-
73
import org.openqa.selenium.By;
84
import org.openqa.selenium.WebDriver;
95
import org.openqa.selenium.WebElement;
106
import org.openqa.selenium.firefox.FirefoxDriver;
117

8+
import java.util.List;
9+
import java.util.concurrent.TimeUnit;
10+
1211
public class SeleniumExample {
1312

1413
private WebDriver webDriver;
@@ -38,12 +37,11 @@ public void getAboutBaeldungPage() {
3837

3938
private void closeOverlay() {
4039
List<WebElement> webElementList = webDriver.findElements(By.tagName("a"));
41-
try {
42-
if (webElementList != null && !webElementList.isEmpty()) {
43-
webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().orElseThrow(NoSuchElementException::new).click();
44-
}
45-
} catch (NoSuchElementException exception) {
46-
exception.printStackTrace();
40+
if (webElementList != null) {
41+
webElementList.stream()
42+
.filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title")))
43+
.findAny()
44+
.ifPresent(WebElement::click);
4745
}
4846
}
4947

0 commit comments

Comments
 (0)