Bug 4339: Ensures that we wait for validation in dialogs and click the

ok button after it is scrolled into view and active
This commit is contained in:
Steffen Schaefer committed 2018-07-23 15:02:48 +02:00
1 parent 2a99cc8319
commit f00a4325ef
2 files changed
+9 -2

No files matched your search

@@ -630,8 +630,10 @@ public class PageObject {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(false);", webElement);
}
protected void scrollToViewAndClick(WebElement webElement) {
protected void scrollToViewAndClickWhenElementIsEntirelyVisible(WebElement webElement) {
scrollToView(webElement);
// Browsers may use smooth scrolling
new WebDriverWait(driver, 10).until(t -> isElementEntirelyVisible(webElement));
webElement.click();
}
@@ -1,6 +1,7 @@
package com.sap.sailing.selenium.pages.common;
import org.openqa.selenium.Alert;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
@@ -57,7 +58,11 @@ public abstract class DataEntryDialogPO extends PageArea {
}
public void pressOk(boolean accept) {
scrollToViewAndClick(this.okButton);
// This generically triggers revalidation in dialogs to ensure that the ok button gets enabled
((JavascriptExecutor) driver).executeScript("!!document.activeElement ? document.activeElement.blur() : 0");
scrollToViewAndClickWhenElementIsEntirelyVisible(this.okButton);
new WebDriverWait(driver, 10).until(driver -> this.okButton.isEnabled());
ExpectedCondition<Alert> condition = ExpectedConditions.alertIsPresent();
Alert alert = condition.apply(this.driver);