File tree Expand file tree Collapse file tree
selenium-junit-testng/src/main/java/com/baeldung/selenium Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package main .java .com .baeldung .selenium ;
22
33import java .util .List ;
4+ import java .util .NoSuchElementException ;
45import java .util .concurrent .TimeUnit ;
56
67import org .openqa .selenium .By ;
@@ -28,16 +29,16 @@ public String getTitle() {
2829 return webDriver .getTitle ();
2930 }
3031
31- public void getAboutBaeldungPage () {
32+ public void getAboutBaeldungPage () throws Exception {
3233 closeOverlay ();
3334 clickAboutLink ();
3435 clickAboutUsLink ();
3536 }
3637
37- private void closeOverlay () {
38+ private void closeOverlay () throws Exception {
3839 List <WebElement > webElementList = webDriver .findElements (By .tagName ("a" ));
39- if (webElementList != null && !webElementList .isEmpty ()) {
40- webElementList .stream ().filter (webElement -> "Close" .equalsIgnoreCase (webElement .getAttribute ("title" ))).findAny ().get ( ).click ();
40+ if (webElementList != null && !webElementList .isEmpty () && webElementList . stream (). filter ( webElement -> "Close" . equalsIgnoreCase ( webElement . getAttribute ( "title" ))). findAny (). isPresent () ) {
41+ webElementList .stream ().filter (webElement -> "Close" .equalsIgnoreCase (webElement .getAttribute ("title" ))).findAny ().orElseThrow ( NoSuchElementException :: new ).click ();
4142 }
4243 }
4344
@@ -50,8 +51,6 @@ private void clickAboutUsLink() {
5051 }
5152
5253 public boolean isAuthorInformationAvailable () {
53- return webDriver
54- .findElement (By .xpath ("//*[contains(text(), 'Eugen – an engineer')]" ))
55- .isDisplayed ();
54+ return webDriver .findElement (By .xpath ("//*[contains(text(), 'Eugen – an engineer')]" )).isDisplayed ();
5655 }
5756}
You can’t perform that action at this time.
0 commit comments