1313
1414package solutions .bellatrix .web .components .shadowdom ;
1515
16- import lombok .SneakyThrows ;
1716import lombok .experimental .UtilityClass ;
18- import org .jsoup .Jsoup ;
19- import org .jsoup .nodes .Element ;
20- import org .jsoup .select .Elements ;
2117import org .openqa .selenium .By ;
2218import solutions .bellatrix .core .configuration .ConfigurationService ;
23- import solutions .bellatrix .core .utilities .HtmlService ;
2419import solutions .bellatrix .core .utilities .InstanceFactory ;
2520import solutions .bellatrix .core .utilities .Ref ;
2621import solutions .bellatrix .core .utilities .Wait ;
3227
3328import java .time .Duration ;
3429import java .util .ArrayList ;
35- import java .util .Arrays ;
3630import java .util .List ;
3731import java .util .Stack ;
3832import java .util .concurrent .Callable ;
39- import java .util .stream .Collectors ;
4033
4134@ UtilityClass
4235public class ShadowDomService {
@@ -198,18 +191,14 @@ private static int getNestedLevel(WebComponent component) {
198191 }
199192
200193 private static String retraceParentShadowRoots (WebComponent component ) {
201- if (getNestedLevel (component ) > 1 ) {
194+ if (getNestedLevel (component ) > 1 && component . inShadowContext () ) {
202195 var parent = component .getParentComponent ();
203196
204197 Stack <String > findStrategies = new Stack <>();
205198
206- checkIfCss (component .getFindStrategy ());
207-
208199 findStrategies .push (component .getFindStrategy ().getValue ());
209200
210- while (parent instanceof ShadowRoot ) {
211- checkIfCss (parent .getFindStrategy ());
212-
201+ while (parent instanceof ShadowRoot && parent .inShadowContext ()) {
213202 findStrategies .push (CHILD_COMBINATOR + SHADOW_ROOT_TAG + CHILD_COMBINATOR );
214203 findStrategies .push (parent .getFindStrategy ().getValue ());
215204
@@ -227,12 +216,10 @@ private static String retraceParentShadowRoots(WebComponent component) {
227216 }
228217 }
229218
230- private static void checkIfCss (FindStrategy findStrategy ) {
219+ private static boolean checkIfCss (FindStrategy findStrategy ) {
231220 var strategyType = findStrategy .convert ();
232221
233- if (strategyType instanceof By .ByLinkText || strategyType instanceof By .ByPartialLinkText ) {
234- throw new IllegalArgumentException ("Inside Shadow DOM, there cannot be anything different than CSS locator." );
235- }
222+ return !(strategyType instanceof By .ByLinkText ) && !(strategyType instanceof By .ByPartialLinkText ) && !(strategyType instanceof By .ByXPath );
236223 }
237224
238225 private static String convertToCssOrXpath (FindStrategy findStrategy ) {
0 commit comments