File tree Expand file tree Collapse file tree
src/main/java/com/baeldung/selenium Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5353 <dependency >
5454 <groupId >org.seleniumhq.selenium</groupId >
5555 <artifactId >selenium-java</artifactId >
56- <version >2.53 .1</version >
56+ <version >3.0 .1</version >
5757 </dependency >
5858 <dependency >
5959 <groupId >junit</groupId >
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ public class SeleniumExample {
1515 private String url = "http://www.baeldung.com/" ;
1616
1717 public SeleniumExample () {
18+ System .setProperty ("webdriver.firefox.marionette" , "C:\\ selenium\\ geckodriver.exe" );
1819 webDriver = new FirefoxDriver ();
1920 webDriver .manage ().window ().maximize ();
2021 webDriver .manage ().timeouts ().implicitlyWait (10 , TimeUnit .SECONDS );
@@ -29,16 +30,20 @@ public String getTitle() {
2930 return webDriver .getTitle ();
3031 }
3132
32- public void getAboutBaeldungPage () throws Exception {
33+ public void getAboutBaeldungPage () {
3334 closeOverlay ();
3435 clickAboutLink ();
3536 clickAboutUsLink ();
3637 }
3738
38- private void closeOverlay () throws Exception {
39+ private void closeOverlay () {
3940 List <WebElement > webElementList = webDriver .findElements (By .tagName ("a" ));
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 ();
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 ();
4247 }
4348 }
4449
You can’t perform that action at this time.
0 commit comments