Skip to content

[🐛 Bug]: Incompatibilities between Selenium 4.12 and lodash (and underscore-js/angular) #12812

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

Closed
ShaheedHaque opened this issue Sep 22, 2023 · 9 comments
Labels
I-defect Something is not working as intended

Comments

@ShaheedHaque
Copy link

What happened?

This relates to https://groups.google.com/g/selenium-users/c/KY0hJ8U-Iu4/m/uG5DyA6XAQAJ. The original issue was reported by another user with regard to underscore-js/angular, but I am specifically having what seems to be the same issue with lodash, and this report reflects that.

  1. Our tests run fine with Selenium 4.10.0 but break with Selenium 4.12.0. (There may or may not be breakage with 4.11.x).
  2. Of several breakages, in one case, we get this:
    selenium.common.exceptions.JavascriptException: Message: javascript error: _.isEqual is not a function
    
    Here is the test script fragment:
    self.driver.execute_script("$('#" + id + "').val('" + date + "'); $('#" + id + "').change();")
    
    >>>    date     = '2018-07-20'
    >>>    id         = 'id_pay_period_last_day'
    
    In other words, we are using jQuery via execute_script() to find a date element by id, and then set it value.
  3. In another case we see:
    selenium.common.exceptions.JavascriptException: Message: javascript error: _.cloneDeep is not a function
    
    Here is the test script fragment:
     try:
         element.clear()
         element.send_keys(entry)
     except ElementNotInteractableException:
         ...
         assert heading == 'id_inputs-0-value'
         driver.execute_script('$("#' + heading + '").val(`' + entry + '`).change()')
    
    >>> entry         = 'some string'
    >>> heading    = 'id_inputs-0-value'
    
    In other words, we are using jQuery via execute_script() to set a textarea to some string.

Although we do use lodash and thus "_", I note that these two execute_script() invocations do not reference lodash directly. However, lodash is probably being invoked via the .change().

Taken together with the original report, it seems that 4.12 (or maybe 4.11) introduced some issue related to the use of an underscore. I checked the release notes but could not see any obvious smoking gun.

How can we reproduce the issue?

I believe a script like this may show the error:


driver.execute_script("$('#id_start_date').val('2022-12-01').change();")

given that the HTML contains something like

<html>
<head>
    <script src=".whatever.../jquery.min.js"></script>
    <script src="..whatever.../lodash.min.js"></script>
</head>
<body>    
    <input type="date" value="2018-01-01" id="id_start_date">

    <script>
    $("#id_start_date").change(function() {
        const foo = {};
        if (_.isEmpty(foo)) {
            console.log("hello");
        };
    });
    </script>
</body>


### Relevant log output

```shell
Traceback (most recent call last):
  File "/main/srhaque/repo/source/test/browser.py", line 721, in upload_by_add
    self.set_date(heading, entry)
  File "/main/srhaque/repo/source/test/browser.py", line 875, in set_date
    self.driver.execute_script("$('#" + id + "').val('" + date + "'); $('#" + id + "').change();")
  File "/main/srhaque/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 404, in execute_script 
    return self.execute(command, {"script": script, "args": converted_args})["value"]
  File "/main/srhaque/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 344, in execute
    self.error_handler.check_response(response) 
  File "/main/srhaque/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: javascript error: _.isEqual is not a function 
  (Session info: chrome=116.0.5845.96)
Stacktrace:
#0 0x55556493fe23 <unknown>
#1 0x5555646687a7 <unknown>
#2 0x55556466cd1e <unknown>
#3 0x55556466e859 <unknown>
#4 0x5555646e0e4f <unknown>
#5 0x5555646c8012 <unknown>
#6 0x5555646e0369 <unknown>
#7 0x5555646c7de3 <unknown>
#8 0x55556469ba7b <unknown>
#9 0x55556469c81e <unknown>
#10 0x555564901638 <unknown>
#11 0x555564905507 <unknown>
#12 0x55556490fc4c <unknown>
#13 0x555564906136 <unknown>
#14 0x5555648d49cf <unknown>
#15 0x555564929b98 <unknown>
#16 0x555564929d68 <unknown>
#17 0x555564938cb3 <unknown>
#18 0x7f528ed44b43 <unknown>

Operating System

macOS and Ubuntu

Selenium version

Python 4.12.0

What are the browser(s) and version(s) where you see this issue?

Chrome 117

What are the browser driver(s) and version(s) where you see this issue?

Chromedriver 117

Are you using Selenium Grid?

No

@ShaheedHaque ShaheedHaque added I-defect Something is not working as intended A-needs-triaging A Selenium member will evaluate this soon! labels Sep 22, 2023
@ShaheedHaque
Copy link
Author

The original reporter has stated it works for him on 4.11.0 and fails on 4.12.0. (https://groups.google.com/g/selenium-users/c/KY0hJ8U-Iu4/m/jfwE7kY9AgAJ)

@github-actions
Copy link

@ShaheedHaque, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@titusfortner
Copy link
Member

This is a duplicate of #12659 and has been fixed in upcoming release

@vbaulac
Copy link

vbaulac commented Sep 28, 2023

Is there a workaround until the new version is released ?

@diemol
Copy link
Member

diemol commented Sep 28, 2023

4.13 has already been released. Closing this.

@diemol diemol closed this as completed Sep 28, 2023
@diemol diemol removed the A-needs-triaging A Selenium member will evaluate this soon! label Sep 28, 2023
@vbaulac
Copy link

vbaulac commented Sep 28, 2023

EDIT : mistake on pipenv

_ is overriden at some point, and therefor I endup with
_.isNil is not a function

Selenium version 4.13.0

@diemol
Copy link
Member

diemol commented Sep 28, 2023

Then please provide a full code sample we can use to reproduce this and then reopen.

@vbaulac
Copy link

vbaulac commented Sep 28, 2023

I am sorry this was a mistake on my side (pipenv mixup...), it is indeed fixed in 4.13.0, sorry about that

Copy link

github-actions bot commented Dec 4, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I-defect Something is not working as intended
Projects
None yet
Development

No branches or pull requests

4 participants