[java-idp-integration-tests] 01/02: Another Chrome click workaround, using JavaScript

Tom Zeller tzeller at dragonacea.biz
Tue Aug 30 18:10:51 UTC 2022


This is an automated email from the git hooks/post-receive script.

tzeller pushed a commit to branch main
in repository java-idp-integration-tests.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=90df64e038280f490786d7b326680fc184bfc78e

commit 90df64e038280f490786d7b326680fc184bfc78e
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Mon Aug 29 22:53:42 2022 -0500

    Another Chrome click workaround, using JavaScript
---
 .../idp/integration/tests/BaseIntegrationTest.java   | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
index 79758c9..5d37655 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
@@ -81,6 +81,7 @@ import org.apache.http.util.EntityUtils;
 import org.openqa.selenium.By;
 import org.openqa.selenium.Dimension;
 import org.openqa.selenium.ElementNotInteractableException;
+import org.openqa.selenium.JavascriptExecutor;
 import org.openqa.selenium.Point;
 import org.openqa.selenium.StaleElementReferenceException;
 import org.openqa.selenium.WebDriver;
@@ -2244,15 +2245,32 @@ public abstract class BaseIntegrationTest {
      * 
      * Catch {@link ElementNotInteractableException} and click via {@link Actions}.
      * 
+     * If element is still not clicked, try JavaScript.
+     * 
      * @param element element to be clicked
+     * @throws RuntimeException if element is not clicked
      */
-    public void clickWorkaround(final WebElement element) {
+    public void clickWorkaround(final WebElement element) throws RuntimeException {
+        boolean isSelected = element.isSelected();
+        log.trace("ClickWorkaround element '{}' isSelected '{}'", element, element.isSelected());
         try {
             element.click();
         } catch (ElementNotInteractableException e) {
             log.trace("Unable to click element {}, will try again", element);
             final Actions action = new Actions(driver);
             action.moveToElement(element).click().build().perform();
+            log.trace("ClickWorkaround element'{}' isSelected '{}'", element, element.isSelected());
+            // If element is still not clicked, try JavaScript
+            if ((isSelected && element.isSelected()) || (!isSelected && !element.isSelected())) {
+                log.trace("Unable to click element '{}', will try JavaScript", element);
+                final JavascriptExecutor js = (JavascriptExecutor) driver;
+                js.executeScript("arguments[0].click();", element);
+            }
+        }
+        // If element is not clicked, throw runtime exception
+        if ((isSelected && element.isSelected()) || (!isSelected && !element.isSelected())) {
+            log.error("Unable to click element '{}'", element);
+            throw new RuntimeException("Unable to click element " + element);
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list