Home>

I am working on automating attendance input to an in-house system with Selenium of Python (3.7).
I want to click the date on the calendar displayed in the browser.
Looking at the source of the page, it's like executing a Javascript function to select it.

Therefore,
driver.execute_script ("fnClickHizuke (2020,11,25,1)")
I wrote it like this, but it didn't recognize the javascript function well,
The following error message has occurred.
How do I write it to execute the fnClickHizuke function?
Please give me some advice.

DevTools listening on ws: //127.0.0.1:65032/devtools/browser/9fcfa227-078d-45c5-90f0-2ec9c89c8891
[18468: 17220: 1125/175755.360: ERROR: device_event_log_impl.cc (211)] [17: 57: 55.360] USB: usb_device_handle_win.cc: 1020 Failed to read descriptor from node connection: The device connected to the system is working not. (0x1F)
[18468: 17220: 1125/175755.370: ERROR: device_event_log_impl.cc (211)] [17: 57: 55.371] USB: usb_device_handle_win.cc: 1020 Failed to read descriptor from node connection: The device connected to the system is working not. (0x1F)
[18468: 17220: 1125/175755.552: ERROR: device_event_log_impl.cc (211)] [17: 57: 55.552] Bluetooth: bluetooth_adapter_winrt.cc: 1204 Getting Radio failed. Chrome will be unable to change the power state by itself.
[18468: 17220: 1125/175755.604: ERROR: device_event_log_impl.cc (211)] [17: 57: 55.605] Bluetooth: bluetooth_adapter_winrt.cc: 1297 OnPoweredRadiosEnumerated (), Number of Powered Radios: 0
Traceback (most recent call last):
  File "0_login.py", line 42, in<module>  driver.execute_script ("fnClickHizuke (2020,11,25,1)")
  File "C: \ Python \ lib \ site-packages \ selenium \ webdriver \ remote \ webdriver.py", line 636, in execute_script
    'args': converted_args}) ['value']
  File "C: \ Python \ lib \ site-packages \ selenium \ webdriver \ remote \ webdriver.py", line 321, in execute
    self.error_handler.check_response (response)
  File "C: \ Python \ lib \ site-packages \ selenium \ webdriver \ remote \ errorhandler.py", line 242, in check_response
    raise exception_class (message, screen, stacktrace)
selenium.common.exceptions.JavascriptException: Message: javascript error: fnClickHizuke is not defined
  (Session info: chrome = 87.0.4280.66)
HTML to be operated (excerpt of the part that seems to be the target)
<! DOCTYPE html><html><head>    <meta charset = "utf-8" /><script><!-
var menujs = (function () {
    window.onPageLoadOrBack (function () {
        menuHaveSubmitted = false;
        logoffHaveSubmitted = false;
    });
    return {// Press the date selection button
        fnClickHizuke: function (year, month, date, flag) {
            // If there is a warning, control it.
            if (top.haveAlert () == true) {
              return false;
            }
            if (date<10) {
                date = "0" + date;
            }
            if (month<10) {
                month = "0" + month;
            }
            document.FORM_MENU.SelectDate.value = String (year) + "/" + String (month) + "/" + String (date);
            return this.go ("WC020", flag);
        },


    };
}) ();
//-></script></head></html>
Code 1 I tried
driver = webdriver.Chrome ("chromedriver.exe")
driver.execute_script ("fnClickHizuke (2020,11,25,1)")
Code 2 I tried
driver = webdriver.Chrome ("chromedriver.exe")
driver.execute_script ("menujs (fnClickHizuke (2020,11,25,1))")
What I tried

I thought that javascript can be executed by using execute_script,
Because I got an error saying fnClickHizuke is not defined
I think I haven't been able to find the fnClickHizuke function.
If it can be recognized well, I will put the year, month, and day in the argument of the fnClickHizuke function.
By the way, this is the next step ...
Since the role of flag, which is the fourth argument of the fnClickHizuke function, is also unknown,
I would be very grateful if I knew what to put in.

Supplementary information (FW/tool version, etc.)

Enter the URL you searched for.
https://qiita.com/nadechin/items/0a34e2182132cc1a821b
https://qiita.com/yiyiaxpb/items/a24708e66a4e0c22b0a6
https://www.tutorialfor.com/go.php?id=212057
https://www.tutorialfor.com/go.php?id=220208

Usage environment
OS: windows10

>python --version
Python 3.7.3

>pip list
Package Version
------------------------- ---------
altgraph 0.17
certifi 2019.3.9
chardet 3.0.4
et-xmlfile 1.0.1
future 0.18.2
html5lib 1.0.1
idna 2.8
jdcal 1.4
lxml 4.3.3
numpy 1.16.2
openpyxl 2.6.2
overlay 1.1.5
pandas 0.24.2
pefile 2019.4.18
pip 20.2.4
pyinstaller 4.1
pyinstaller-hooks-contrib 2020.10
python-dateutil 2.8.0
pytz 2019.1
pywin32-ctypes 0.2.0
requests 2.21.0
selenium 3.141.0
setuptools 40.8.0
six 1.12.0
urllib3 1.24.1
webencodings 0.5.1
wheel 0.35.1
xlrd 1.2.0
zenhan 0.5.2

  • Answer # 1

    menujs.fnClickHizuke (~~)Then?

    SofnClickHizuke is not definedI think it will disappear.
    I don't know if it will work after that.