@@ -124,8 +124,14 @@ public WebElement getWrappedElement() {
124124 } else {
125125 return findElement ();
126126 }
127- } catch (Exception ex ) {
127+ } catch (ElementNotInteractableException ex ) {
128+ scrollToVisible ();
128129 return findElement ();
130+ } catch (StaleElementReferenceException ex ) {
131+ return findElement ();
132+ } catch (WebDriverException ex ) {
133+ toExist ().waitToBe ();
134+ return wrappedElement ;
129135 }
130136 }
131137
@@ -844,7 +850,7 @@ private boolean inShadowContext() {
844850 }
845851
846852 public WebElement findElement () {
847- if (waitStrategies .size () == 0 ) {
853+ if (waitStrategies .isEmpty () ) {
848854 waitStrategies .add (Wait .to ().exist (webSettings .getTimeoutSettings ().getElementWaitTimeout (), webSettings .getTimeoutSettings ().getSleepInterval ()));
849855 }
850856
@@ -893,15 +899,8 @@ private void clickInternal() {
893899 try {
894900 wait .until (x -> tryClick ());
895901 } catch (TimeoutException e ) {
896- Log .info ("Timeout Exception found - retrying... " );
897- toBeVisible ().toBeClickable ().findElement ().click ();
898- } catch (StaleElementReferenceException e ) {
899- Log .info ("StaleElementReference Exception found - retrying with scroll.. " );
900- browserService .scrollToTop ();
901- tryClick ();
902- } catch (Exception e ) {
903- Log .info ("Exception found - retrying with scroll.. " );
904- findElement ().click ();
902+ Log .info ("Click has timed out. Trying with JS click()..." );
903+ javaScriptService .execute ("arguments[0].click()" , findElement ());
905904 }
906905 }
907906
@@ -910,12 +909,15 @@ private boolean tryClick() {
910909 toBeVisible ().toBeClickable ().findElement ().click ();
911910 return true ;
912911 } catch (ElementNotInteractableException e ) {
912+ Log .error ("ElementNotInteractableException found - retrying with scroll.. " );
913+ scrollToVisible ();
913914 return false ;
914915 } catch (StaleElementReferenceException e ) {
916+ Log .error ("StaleElementReference Exception found - retrying with a new Find... " );
915917 findElement ();
916918 return false ;
917919 } catch (WebDriverException e ) {
918- toBeVisible (). toBeClickable (). waitToBe ( );
920+ Log . error ( "WebDriverException found - trying again... " );
919921 return false ;
920922 }
921923 }
@@ -1302,6 +1304,9 @@ private void scrollToVisible(WebElement wrappedElement, boolean shouldWait, Scro
13021304 public boolean isVisible () {
13031305 try {
13041306 return getWrappedElement ().isDisplayed ();
1307+ } catch (StaleElementReferenceException e ) {
1308+ wrappedElement = findElement ();
1309+ return false ;
13051310 } catch (NotFoundException e ) {
13061311 return false ;
13071312 }
0 commit comments