22
33import org .openqa .selenium .By ;
44import org .openqa .selenium .WebDriver ;
5+ import org .openqa .selenium .WebElement ;
56import org .openqa .selenium .support .ui .ExpectedConditions ;
67import org .openqa .selenium .support .ui .WebDriverWait ;
78import org .slf4j .Logger ;
@@ -25,7 +26,7 @@ public static void tolerantType(
2526 try {
2627 new WebDriverWait (
2728 webDriver , TestConfigManager .getInstance ().getWebDriverConfig ().getWebDriverWaitTimeout ())
28- .until (ExpectedConditions .visibilityOfElementLocated (locator )).click ( );
29+ .until (ExpectedConditions .visibilityOfElementLocated (locator )).sendKeys ( textToType );
2930 } catch (Exception e ) {
3031 logger .error ("Encountered an issue while trying to select visible text from select box, will check " +
3132 "to see if we tolerate this exception. Debug this issue to make your tests more stable. " +
@@ -42,7 +43,42 @@ public static void tolerantType(
4243 logger .error ("Waited {} seconds after {}, now retrying" , waitTimeBeforeRetry , exceptionToHandle );
4344 new WebDriverWait (
4445 webDriver , TestConfigManager .getInstance ().getWebDriverConfig ().getWebDriverWaitTimeout ())
45- .until (ExpectedConditions .visibilityOfElementLocated (locator )).click ();
46+ .until (ExpectedConditions .visibilityOfElementLocated (locator )).sendKeys (textToType );
47+ }
48+ }
49+ }
50+ }
51+
52+ /**
53+ *
54+ * @param webDriver active WebDriver
55+ * @param element WebElement to type in
56+ * @param textToType the text to type in the targeted WebElement
57+ * @param waitTimeBeforeRetry time to wait before we retry
58+ * @throws InterruptedException because there's a Thread.sleep here
59+ */
60+ public static void tolerantType (WebDriver webDriver , WebElement element , String textToType , int waitTimeBeforeRetry ) throws InterruptedException {
61+ try {
62+ new WebDriverWait (
63+ webDriver , TestConfigManager .getInstance ().getWebDriverConfig ().getWebDriverWaitTimeout ())
64+ .until (ExpectedConditions .elementToBeClickable (element )).sendKeys (textToType );
65+ } catch (Exception e ) {
66+ logger .error ("Encountered an issue while trying to select visible text from select box, will check " +
67+ "to see if we tolerate this exception. Debug this issue to make your tests more stable. " +
68+ "Stacktrace follows." );
69+ e .printStackTrace ();
70+ for (String exceptionToHandle :
71+ TestConfigManager .getInstance ().getWebDriverConfig ().getExceptionsToHandleOnTolerantActions ()) {
72+ if (e .getClass ().getName ().contains (exceptionToHandle )) {
73+ logger .error (
74+ "Exception {} is tolerated, retrying after a {} second wait" ,
75+ waitTimeBeforeRetry ,
76+ exceptionToHandle );
77+ Thread .sleep (waitTimeBeforeRetry );
78+ logger .error ("Waited {} seconds after {}, now retrying" , waitTimeBeforeRetry , exceptionToHandle );
79+ new WebDriverWait (
80+ webDriver , TestConfigManager .getInstance ().getWebDriverConfig ().getWebDriverWaitTimeout ())
81+ .until (ExpectedConditions .elementToBeClickable (element )).sendKeys (textToType );
4682 }
4783 }
4884 }
0 commit comments