Shadow-Piercing descendant combinator, '/deep/' , including '::shadow' pseudo elements, are being deprecated so how do we pierce the Shadow DOM?
Rather than using <link />
, I'd suggest you to use css @imports inside shadow root to load external stylesheets where ever needed.
I have written an answer here on the topic. Quoting it below for reference.
You can create a style.css and import it in your components by putting
a css @import in your template. There won't be multiple network calls,
since browser is going to cache it when your first component loads and
for subsequent components it will picked from cache.
What's the substitute for ::shadow and /deep/?
::shadow
and /deep/
were removed for breaking encapsulation.
The substitutes are:
- CSS variables.
It already works natively with the recently launched Google Chrome 49. Read here:- http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-201/
- https://developers.google.com/web/updates/2016/02/css-variables-why-should-you-care?hl=en
- http://blog.chromium.org/2016/02/chrome-49-beta-css-custom-properties.html
:host-context
. Read here: http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-201/
The use of /deep/ and in Angular 2
Is /deep/ here to stay? Do we have any source, a quote, or anything from any specification saying that it will be adopted? Or if it has officially been deprecated?
The
/deep/
syntax is obsolete, last seen in css-scoping in 2014, and its replacement>>>
was deprecated about half a year ago in Chrome 45.The entire concept of the shadow-piercing descendant combinator is slated to be removed from the Shadow DOM entirely. Implementations may either remove it altogether or alias it to the regular descendant combinator (which depending on how the Shadow DOM is implemented in the future may or may not make sense).
Can we suppress this error in Visual Studio Code without all-together disabling syntax checking?
Unfortunately not.
Angular allows both in emulated view encapsulation for compatibility purposes, but authors are strongly encouraged to use
>>>
going forward, since/deep/
is technically invalid now, and therefore unsupported in native view encapsulation.
How and where to use ::ng-deep?
Usually /deep/ “shadow-piercing”
combinator can be used to force a style down to child components
. This selector had an alias >>> and now has another one called ::ng-deep.
since /deep/ combinator
has been deprecated, it is recommended to use ::ng-deep
For example:
<div class="overview tab-pane" id="overview" role="tabpanel" [innerHTML]="project?.getContent( 'DETAILS')"></div>
and css
.overview {
::ng-deep {
p {
&:last-child {
margin-bottom: 0;
}
}
}
}
it will be applied to child components
How to automate shadow DOM elements using selenium?
There is a very good plugin that can be used with selenium project shadow-automation-selenium. It helps in writing much better, readable and maintainable code. Using this you can access multi level of shadow DOM (upto 4 levels ) . This uses simple css selector to identify elements.
WebElement findElement(String cssSelector)
: use this method if want single element from DOM
List<WebElement> findElements(String cssSelector)
: use this if you want to find all elements from DOM
WebElement findElements(WebElement parent, String cssSelector)
: use this if you want to find a single elements from parent object DOM
List<WebElement> findElements(WebElement parent, String cssSelector)
: use this if you want to find all elements from parent object DOM
WebElement getShadowElement(WebElement parent,String selector)
: use this if you want to find a single element from parent DOM
List<WebElement> getAllShadowElement(WebElement parent,String selector)
: use this if you want to find all elements from parent DOM
boolean isVisible(WebElement element)
: use this if you want to find visibility of element
boolean isChecked(WebElement element)
: use this if you want to check if checkbox is selected
boolean isDisabled(WebElement element)
: use this if you want to check if element is disabled
String getAttribute(WebElement element,String attribute)
: use this if you want to get attribute like aria-selected and other custom attributes of elements.
void selectCheckbox(String label)
: use this to select checkbox element using label.
void selectCheckbox(WebElement parentElement, String label)
: use this to select checkbox element using label.
void selectRadio(String label)
: use this to select radio element using label.
void selectRadio(WebElement parentElement, String label)
: use this to select radio element from parent DOM using label.
void selectDropdown(String label)
: use this to select dropdown list item using label (use this if only one dropdown is present or loaded on UI).
void selectDropdown(WebElement parentElement, String label)
: use this to select dropdown list item from parent DOM using label.
How to use this plugin:
You will have to dependency in your project.
Maven
<dependency>
<groupId>io.github.sukgu</groupId>
<artifactId>automation</artifactId>
<version>0.0.4</version>
<dependency>
for html tag that resides under a shadow-root dom element
<properties-page id="settingsPage">
<textarea id="textarea">
</properties-page>
You can use this code in your framework to grab the textarea element Object.
import io.github.sukgu.*;
Shadow shadow = new Shadow(driver);
WebElement element = shadow.findElement("properties-page#settingsPage>textarea#textarea");
String text = element.getText();
Related Topics
Make :Focus Change CSS of Another Class
Dropdown Checkboxes and Unchecked Parents Element
Jquery .Css() Function Not Returning Expected Values
How to Dynamically Change the Value of a CSS Property Inside a Stylesheet
Isotope Jquery Plugin Doesn't Show Properly on Chrome
How to Jump to Top of Browser Page
Bootstrap Dropdown Checkbox Select
Animate CSS3 Gradient-Positions Using Jquery
Jquery Calendar Time Selection Suggestion
Bootstrap 3.0 Popovers and Tooltips
How to Add a CSS Class to a Raphael Object
Prevent Scroll Bounce for the Body Element, But Keep It for Child Elements in iOS
Implementing Transition Effects in React Js When State Changes
Amcharts - Line Chart Overflowing Graph Container
How to Clear React-Native Cache
Horizontal Swipe Slider with Jquery and Touch Devices Support