function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Imran ChowdhryImran Chowdhry 

Why is Selenium/JS/JQuery unable to locate elements in Winter 2020 release of Salesforce?

Hello,

I have built an automation tool to help with regression testing, and so far it works without any issues in the Summer 19' release. I had a sandbox reserved to test the automation tool in the Winter 2020 release, and I am unable to locate multi-select picklists and custom forums under related lists in the Winter 2020 preview of Salesforce.

I have used Selenium functions to locate elements, JavaScript, and JQuery, all which work on the Summer 19 release but not the Winter 2020 release.

User-added imageAAs you can see, I am able to locate the same value in the multi-select picklist with no issues..

User-added imageI am unable to locate the elements that I was able to locate in Summer 2019

Does anyone have any idea why this may be happening?
Best Answer chosen by Imran Chowdhry
Alain CabonAlain Cabon

DOM API Changes
Shadow DOM is a standard that encapsulates the internal document object model (DOM) structure of a web component. The internal DOM structure is called the shadow tree. In Winter ’20, code can’t use document or document.body to access the shadow tree of a Lightning web component.
Per the Shadow DOM specification, elements in a shadow tree aren’t accessible via traditional DOM querying methods. To access its own shadow tree, a Lightning web component uses this.template.querySelector().

For example, code in a test can’t call document.querySelector() to select nodes in a Lightning web component’s shadow tree.

http://salesforcecodex.com/2019/08/salesforce-winter-20-release-feature-enhancements-for-development/
 

All Answers

Alain CabonAlain Cabon

DOM API Changes
Shadow DOM is a standard that encapsulates the internal document object model (DOM) structure of a web component. The internal DOM structure is called the shadow tree. In Winter ’20, code can’t use document or document.body to access the shadow tree of a Lightning web component.
Per the Shadow DOM specification, elements in a shadow tree aren’t accessible via traditional DOM querying methods. To access its own shadow tree, a Lightning web component uses this.template.querySelector().

For example, code in a test can’t call document.querySelector() to select nodes in a Lightning web component’s shadow tree.

http://salesforcecodex.com/2019/08/salesforce-winter-20-release-feature-enhancements-for-development/
 
This was selected as the best answer
Alain CabonAlain Cabon
The big problem is that "this.template.querySelector()" is not equivalent to "document.querySelector()" by just adding "template".

"To access its own shadow tree": strong constraint.

Working with Shadow DOM Elements using Webdriver
https://www.seleniumeasy.com/selenium-tutorials/accessing-shadow-dom-elements-with-webdriver

 If you look at the DOM structure, every element that has ShadowDOM also has a shadowRoot property which describes the underlying elements.
... but it is very restricted even if you get the shadowRoot property.