Properties may not be accessed on strict mode

Viewed 530

Been looking in the internet for this issue, without finding something that can solve it.

I am using Selenium to access a webpage using ChromeDriver. Everything's working fine, until I try to execute JS-script in console:

browser.execute_script('javascript:__doPostBack(\'ctl00$BodyRegion$PageRegion$MainRegion$Loginlink\',\'\')')

This works fine when I'm trying to run it on my browser. But in Selenium, I keep getting this error:

selenium.common.exceptions.JavascriptException: Message: javascript error: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them (Session info: headless chrome=95.0.4638.54)

Does this mean the issue is in the webpage or Selenium/Chromedriver?

Any help is appreciated!

1 Answers

It seems that this error is caused by the javascript on the website and not because of selenium.

Take a look at this, https://www.w3schools.com/js/js_strict.asp

It says that:

The "use strict" directive was new in ECMAScript version 5. It is not a statement, but a literal expression, ignored by earlier versions of JavaScript. The purpose of "use strict" is to indicate that the code should be executed in "strict mode". With strict mode, you can not, for example, use undeclared variables.

Maybe you could try something like this,

item = driver.execute_script("""
  return document.querySelector('[onclick*="\'ctl00$BodyRegion$PageRegion$MainRegion$Loginlink\',\'\'"]')
"""
item.click()
Related