javascript error: Cannot read properties of undefined (reading 'defaultView')\n OpenQA.Selenium.JavaScriptException

2,981 views
Skip to first unread message

Justin Wagner

unread,
Jun 6, 2022, 3:26:29 PM6/6/22
to ChromeDriver Users
Automating tests against Salesforce right now and having an issue clicking on the tabs on the main page. I can find the element successfully using xpath and both the displayed and enabled properties of the element are true. When the Click() happens it throws an exception:

javascript error: Cannot read properties of undefined (reading 'defaultView')\n OpenQA.Selenium.JavaScriptException

If I click on the element using javascript the click works:

js.ExecuteScript("arguments[0].click();", element);

I would prefer to use the standard Click() in my code so I'm wondering if anyone knows what might be causing this? I've read other posts about it being an issue with previous versions of Chrome but I'm currently using Chrome 102.0.5005.63 and ChromeDriver 102.0.5005.61.

Fabian Knittel

unread,
Jul 13, 2022, 12:42:16 PM7/13/22
to ChromeDriver Users
Hi all,

we've hit this within our own website too. The above "javascript error: Cannot read properties of undefined (reading 'defaultView')" exception appears to be thrown as soon as the effectively clicked element is a direct child of a shadow DOM root. (Using https://w3c.github.io/webdriver/#element-click on the a-element or any element within the a-element.)

Not working:
  <body>
    <some-custom-element>
      #shadow-root
      <a href="https://example.org/">
        <div>...</div>
      </a>
    </some-custom-element>
  </body>

Working:
  <body>
    <some-custom-element>
      #shadow-root
      <div>
        <a href="https://example.org/">
          <div>...</div>
        </a>
      </div>
    </some-custom-element>
  </body>

Using executeScript or https://www.w3.org/TR/webdriver/#actions to click works for both scenarios. Any ideas?

Currently using Chrome 103.0.5060.114 and ChromeDriver 103.0.5060.53.

Cheers, Fabian

Fabian Knittel

unread,
Jul 13, 2022, 12:54:35 PM7/13/22
to ChromeDriver Users
Looks very similar to https://bugs.chromium.org/p/chromedriver/issues/detail?id=3684 - unfortunately the referenced C++ code and docs didn't help me in identifying/understanding the underlying problem.

Space Soft System

unread,
Jul 14, 2022, 5:39:58 AM7/14/22
to Fabian Knittel, ChromeDriver Users
  hello sir / madam

We have tried many times to contact you. I am Microsoft Visual Basic 2019 developer , and I am just learning Whatsapp automation. I use google search and youtube for whatsapp automation code and javascript code. 75% my code done for whatsapp automation but now i want add whatsapp button message like https://github.com/adiwajshing/Baileys 

adiwajshing Baileys use node js but i want same function in microsoft visual basic 2019 

its possible , if yes then please share code 

i send same mail to https://visualstudio.microsoft.com/vs/support/# but no any update tile now , today i send again , 


please reply me as soon as possible


--
You received this message because you are subscribed to the Google Groups "ChromeDriver Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromedriver-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chromedriver-users/28c00932-f1d9-4d6b-a034-78f90abe46dcn%40googlegroups.com.


--
===============================================
Space Soft System
Software Development Work
Software Sales & Service

Cell 73546-73546
Reply all
Reply to author
Forward
0 new messages