Skip to content

Commit ddee362

Browse files
committed
fix(functions): fix contenteditable vs .val() issues on firefox
1 parent 4ef0979 commit ddee362

2 files changed

Lines changed: 4 additions & 21 deletions

File tree

‎src/main/java/io/github/seleniumquery/functions/jquery/forms/ValFunction.java‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@
3535

3636
import org.apache.commons.logging.Log;
3737
import org.apache.commons.logging.LogFactory;
38-
import org.openqa.selenium.ElementNotVisibleException;
3938
import org.openqa.selenium.JavascriptExecutor;
4039
import org.openqa.selenium.Keys;
4140
import org.openqa.selenium.WebDriver;
4241
import org.openqa.selenium.WebDriverException;
4342
import org.openqa.selenium.WebElement;
44-
import org.openqa.selenium.firefox.FirefoxDriver;
4543
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
4644
import org.openqa.selenium.support.ui.Select;
4745

@@ -117,7 +115,7 @@ private static void changeElementValue(WebDriver driver, WebElement element, Str
117115
changeValueOfInputElement(element, value);
118116
} else if (isOptionTag(element)) {
119117
warnAboutNotChangingValueOfElement("<option>", "#myOption");
120-
} else if (isContentEditable(element)) {
118+
} else if (isContentEditable(driver, element)) {
121119
changeValueOfContentEditableElement(driver, element, value);
122120
} else {
123121
changeValueOfUnknownElement(element, value);
@@ -156,18 +154,6 @@ private static void changeValueOfContentEditableElement(WebDriver driver, WebEle
156154
// #Cross-Driver
157155
if (DriverVersionUtils.getInstance().isHtmlUnitDriver(driver)) {
158156
changeContentEditableValueInHtmlUnit(driver, element, value);
159-
} else if (driver instanceof FirefoxDriver) {
160-
// #Cross-Driver
161-
// in firefox, an editable div cannot be empty
162-
try {
163-
selectAllText(element);
164-
element.sendKeys(value);
165-
} catch (ElementNotVisibleException e) {
166-
// we could work it out, possibly via JavaScript, but we decided not to, as the END USER would not be able to edit it as well!
167-
throw new ElementNotVisibleException("Empty contenteditable elements are not visible in Firefox, " +
168-
"so a user can't directly interact with them. Try picking an element before the contenteditable one " +
169-
"and sending the TAB key to it, so the focus is switched, and then try calling .val() to change its value.", e);
170-
}
171157
} else {
172158
element.clear();
173159
element.sendKeys(value);

‎src/test/java/endtoend/functions/jquery/forms/val/ValFunction_ContentEditableTest.java‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323
import static testinfrastructure.testutils.DriverInTest.isFirefoxDriver;
2424
import static testinfrastructure.testutils.DriverInTest.isIEDriver;
2525
import static testinfrastructure.testutils.DriverInTest.isOperaDriver;
26-
import static testinfrastructure.testutils.DriverInTest.isRemoteDriver;
2726

2827
import org.junit.ClassRule;
2928
import org.junit.Rule;
3029
import org.junit.Test;
31-
import org.openqa.selenium.ElementNotVisibleException;
30+
import org.openqa.selenium.InvalidElementStateException;
3231
import org.openqa.selenium.WebDriver;
3332

3433
import testinfrastructure.junitrule.SetUpAndTearDownDriver;
@@ -118,7 +117,7 @@ public void val_readAndWrite___divWithContentEditableAttribute___with_EMPTY_STAR
118117
verifyEditableDivAcceptsHtmlCharsCorrectly("#editable-empty", "");
119118
}
120119

121-
@Test(expected = ElementNotVisibleException.class)
120+
@Test(expected = InvalidElementStateException.class)
122121
@FirefoxOnly
123122
public void val_readAndWrite___divWithContentEditableAttribute___with_EMPTY_STARTING_VALUE__hasProblemsOnFirefox() {
124123
verifyEditableDivAcceptsHtmlCharsCorrectly("#editable-empty", "");
@@ -141,10 +140,8 @@ private String addCharsDependingOnDriver(String resultingHtml) {
141140
WebDriver driver = $.driver().get();
142141
if (isIEDriver(driver)) {
143142
return " " + resultingHtml;
144-
} else if ((isFirefoxDriver(driver) && isRemoteDriver(driver)) || isOperaDriver(driver)) {
143+
} else if (isFirefoxDriver(driver) || isOperaDriver(driver)) {
145144
return resultingHtml + " ";
146-
} else if (isFirefoxDriver(driver)) {
147-
return resultingHtml + "<br>";
148145
}
149146
return resultingHtml;
150147
}

0 commit comments

Comments
 (0)