13
13
14
14
package solutions .bellatrix .web .components .shadowdom ;
15
15
16
- import lombok .SneakyThrows ;
17
16
import lombok .experimental .UtilityClass ;
18
- import org .jsoup .Jsoup ;
19
- import org .jsoup .nodes .Element ;
20
- import org .jsoup .select .Elements ;
21
17
import org .openqa .selenium .By ;
22
18
import solutions .bellatrix .core .configuration .ConfigurationService ;
23
- import solutions .bellatrix .core .utilities .HtmlService ;
24
19
import solutions .bellatrix .core .utilities .InstanceFactory ;
25
20
import solutions .bellatrix .core .utilities .Ref ;
26
21
import solutions .bellatrix .core .utilities .Wait ;
32
27
33
28
import java .time .Duration ;
34
29
import java .util .ArrayList ;
35
- import java .util .Arrays ;
36
30
import java .util .List ;
37
31
import java .util .Stack ;
38
32
import java .util .concurrent .Callable ;
39
- import java .util .stream .Collectors ;
40
33
41
34
@ UtilityClass
42
35
public class ShadowDomService {
@@ -198,18 +191,14 @@ private static int getNestedLevel(WebComponent component) {
198
191
}
199
192
200
193
private static String retraceParentShadowRoots (WebComponent component ) {
201
- if (getNestedLevel (component ) > 1 ) {
194
+ if (getNestedLevel (component ) > 1 && component . inShadowContext () ) {
202
195
var parent = component .getParentComponent ();
203
196
204
197
Stack <String > findStrategies = new Stack <>();
205
198
206
- checkIfCss (component .getFindStrategy ());
207
-
208
199
findStrategies .push (component .getFindStrategy ().getValue ());
209
200
210
- while (parent instanceof ShadowRoot ) {
211
- checkIfCss (parent .getFindStrategy ());
212
-
201
+ while (parent instanceof ShadowRoot && parent .inShadowContext ()) {
213
202
findStrategies .push (CHILD_COMBINATOR + SHADOW_ROOT_TAG + CHILD_COMBINATOR );
214
203
findStrategies .push (parent .getFindStrategy ().getValue ());
215
204
@@ -227,12 +216,10 @@ private static String retraceParentShadowRoots(WebComponent component) {
227
216
}
228
217
}
229
218
230
- private static void checkIfCss (FindStrategy findStrategy ) {
219
+ private static boolean checkIfCss (FindStrategy findStrategy ) {
231
220
var strategyType = findStrategy .convert ();
232
221
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 );
236
223
}
237
224
238
225
private static String convertToCssOrXpath (FindStrategy findStrategy ) {
0 commit comments