Merge pull request #763 from Sandeep4odesk/master
Handling Optional as per orElseThrow criteria
This commit is contained in:
commit
a44be73deb
|
@ -1,6 +1,7 @@
|
||||||
package main.java.com.baeldung.selenium;
|
package main.java.com.baeldung.selenium;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
|
@ -28,16 +29,16 @@ public class SeleniumExample {
|
||||||
return webDriver.getTitle();
|
return webDriver.getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getAboutBaeldungPage() {
|
public void getAboutBaeldungPage() throws Exception {
|
||||||
closeOverlay();
|
closeOverlay();
|
||||||
clickAboutLink();
|
clickAboutLink();
|
||||||
clickAboutUsLink();
|
clickAboutUsLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeOverlay() {
|
private void closeOverlay() throws Exception {
|
||||||
List<WebElement> webElementList = webDriver.findElements(By.tagName("a"));
|
List<WebElement> webElementList = webDriver.findElements(By.tagName("a"));
|
||||||
if (webElementList != null && !webElementList.isEmpty()) {
|
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().get().click();
|
webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().orElseThrow(NoSuchElementException::new).click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +51,6 @@ public class SeleniumExample {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAuthorInformationAvailable() {
|
public boolean isAuthorInformationAvailable() {
|
||||||
return webDriver
|
return webDriver.findElement(By.xpath("//*[contains(text(), 'Eugen – an engineer')]")).isDisplayed();
|
||||||
.findElement(By.xpath("//*[contains(text(), 'Eugen – an engineer')]"))
|
|
||||||
.isDisplayed();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue