Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$.select* methods do not work in Internet Explorer #2042

Open
asolntsev opened this issue Dec 2, 2022 · 5 comments
Open

$.select* methods do not work in Internet Explorer #2042

asolntsev opened this issue Dec 2, 2022 · 5 comments

Comments

@asolntsev
Copy link
Member

asolntsev commented Dec 2, 2022

The problem

In Selenide 6.10.1, method $.selectOptionContainingText() causes javascript errors in Windows 10 IE.

Details

If necessary, describe the problem you have been experiencing in more detail.

Tell us about your environment

  • Selenide Version: 6.10.1
  • IE Version: 10
  • OS Version: Windows 11

Code To Reproduce Issue [ Good To Have ]

Configuration.baseUrl = "https://www.w3docs.com/";
Selenide.open("/learn-html/html-select-tag.html");
$("select")
        .scrollIntoView(false)
        .selectOptionContainingText("PHP");

// ok: Selenide 6.9.0, Windows 11 Chrome 107
// ok: Selenide 6.9.0, Windows 11 IE 10
// ok: Selenide 6.10.1, Windows 11 Chrome 107
// NG: Selenide 6.10.1, Windows 11 IE 10

Error stack trace

JavascriptException: Error executing JavaScript
Screenshot: file:/Users/masashi.kondo/miidas/e2e/build/reports/tests/1669957828492.0.png
Page source: file:/Users/masashi.kondo/miidas/e2e/build/reports/tests/1669957828492.0.html
Timeout: 4 s.
Caused by: JavascriptException: Error executing JavaScript
JavascriptException: Error executing JavaScript
Screenshot: file:/Users/masashi.kondo/miidas/e2e/build/reports/tests/1669957828492.0.png
Page source: file:/Users/masashi.kondo/miidas/e2e/build/reports/tests/1669957828492.0.html
Timeout: 4 s.
Caused by: JavascriptException: Error executing JavaScript
	at app//com.codeborne.selenide.ex.UIAssertionError.wrapToUIAssertionError(UIAssertionError.java:103)
	at app//com.codeborne.selenide.ex.UIAssertionError.wrapThrowable(UIAssertionError.java:86)
	at app//com.codeborne.selenide.ex.UIAssertionError.wrap(UIAssertionError.java:80)
	at app//com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:92)
	at app//jp.miidas.e2e.sample.SelenideTest.testSelectBS(SelenideTest.java:238)
Caused by: org.openqa.selenium.JavascriptException: Error executing JavaScript
Build info: version: '4.6.0', revision: '79f1c02ae20'
System info: os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '12.6', java.version: '18.0.2'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [cd5fc84622969cbfa5b45ea60127d4b9a4872529, executeScript {script=return (function (select, texts) {
  if (select.disabled) {
    return {disabledSelect: 'Cannot select option in a disabled select'};
  }

  function optionByText(requestedText) {
    return Array.from(select.options).find(option => option.text.includes(requestedText))
  }

  const missingOptionsTexts = texts.filter(text => !optionByText(text));
  if (missingOptionsTexts.length > 0) {
    return {optionsNotFound: missingOptionsTexts};
  }

  const disabledOptionsTexts = texts.filter(text => optionByText(text).disabled);
  if (disabledOptionsTexts.length > 0) {
    return {disabledOptions: disabledOptionsTexts};
  }

  for (let requestedPartialText of texts) {
    optionByText(requestedPartialText).selected = 'selected';
  }

  const event = document.createEvent('HTMLEvents');
  event.initEvent('change', true, true);
  select.dispatchEvent(event);

  return {};
})(arguments[0], arguments[1])

, args=[{ELEMENT=4305e136-7150-43bd-bf76-563ec8d24eea, element-6066-11e4-a52e-4f735466cecf=4305e136-7150-43bd-bf76-563ec8d24eea}, [PHP]]}]
	at app//com.codeborne.selenide.impl.JavaScript.execute(JavaScript.java:28)
	at app//com.codeborne.selenide.commands.SelectOptionContainingText.execute(SelectOptionContainingText.java:30)
	at app//com.codeborne.selenide.commands.SelectOptionContainingText.execute(SelectOptionContainingText.java:21)
	... 1 more
@cocorossello
Copy link
Contributor

cocorossello commented Dec 2, 2022

I can also see some ajax events not executing (latest chrome) with this new implementation, since 6.10.0. Is there any way to opt-out?

@asolntsev
Copy link
Member Author

asolntsev commented Dec 2, 2022

@cocorossello Could you please specify what means "ajax events"? We need to fix the problem, please help us.

@cocorossello
Copy link
Contributor

We have a jsf application. I can see differences in how ajax events are fired in a select

                            <h:selectOneMenu ....>
                                <f:selectItem noSelectionOption="true" itemLabel="#{originMsg}" />
                                <p:ajax update="@(.some-class)"/>
                            </h:selectOneMenu>

I can see that with 6.10.0 this ajax event is not fired, previous versions were firing it.

I will try to make a reproducer over the weekend if I have the time.

@cocorossello
Copy link
Contributor

This is a very basic reproducer:

    /**
     * This works with selenide 6.9.0 and does not work with selenide 6.10.1, Tested with windows 11, chrome 108
     */
    @Test
    public void onblur_test() {
        open("https://cocorossello.w3spaces.com/select-onblur-selenide.html");
        $("select").selectOptionByValue("2");
        $("body").click();
        $("body").shouldHave(text("after blur"));
    }

I'm sorry for hijacking this issue, it's not the same bug but it's related to the same patch. Do you want me to open another issue?

@cocorossello
Copy link
Contributor

I have created an issue and provided a possible solution for the event problem. We may have to take more events into account, I'm not sure

@asolntsev asolntsev added this to the 6.10.2 milestone Dec 4, 2022
asolntsev added a commit that referenced this issue Dec 4, 2022
P.S. It's not the final solution. We also need to
1. Extract duplicate code to a single place
2. Update code for triggering JS events to support IE.
@asolntsev asolntsev modified the milestones: 6.10.2, 6.11.0 Dec 8, 2022
@asolntsev asolntsev modified the milestones: 6.11.0, 6.12.0 Dec 27, 2022
@asolntsev asolntsev removed this from the 6.12.0 milestone Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants