closeOverlay refactor
This commit is contained in:
parent
b74ce5914b
commit
506bfb9b21
|
@ -1,14 +1,13 @@
|
||||||
package main.java.com.baeldung.selenium;
|
package main.java.com.baeldung.selenium;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class SeleniumExample {
|
public class SeleniumExample {
|
||||||
|
|
||||||
private WebDriver webDriver;
|
private WebDriver webDriver;
|
||||||
|
@ -38,12 +37,11 @@ public class SeleniumExample {
|
||||||
|
|
||||||
private void closeOverlay() {
|
private void closeOverlay() {
|
||||||
List<WebElement> webElementList = webDriver.findElements(By.tagName("a"));
|
List<WebElement> webElementList = webDriver.findElements(By.tagName("a"));
|
||||||
try {
|
if (webElementList != null) {
|
||||||
if (webElementList != null && !webElementList.isEmpty()) {
|
webElementList.stream()
|
||||||
webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().orElseThrow(NoSuchElementException::new).click();
|
.filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title")))
|
||||||
}
|
.findAny()
|
||||||
} catch (NoSuchElementException exception) {
|
.ifPresent(WebElement::click);
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue