Skip to content

Commit e8fa6d3

Browse files
authored
Merge pull request #71 from AutomateThePlanet/navramov_MM
Fix issues with ShadowDOM Locators in nested context
2 parents 4e5353f + e4b645b commit e8fa6d3

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

bellatrix.web/src/main/java/solutions/bellatrix/web/components/WebComponent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,12 +838,12 @@ protected <TComponent extends WebComponent, TFindStrategy extends FindStrategy>
838838
return componentList;
839839
}
840840

841-
private boolean inShadowContext() {
841+
public boolean inShadowContext() {
842842
var component = this;
843843

844-
while (component != null) {
845-
if (component instanceof ShadowRoot) return true;
844+
while (component != null && component.getParentComponent() != null) {
846845
component = component.getParentComponent();
846+
if (component instanceof ShadowRoot) return true;
847847
}
848848

849849
return false;

bellatrix.web/src/main/java/solutions/bellatrix/web/components/shadowdom/ShadowDomService.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@
1313

1414
package solutions.bellatrix.web.components.shadowdom;
1515

16-
import lombok.SneakyThrows;
1716
import lombok.experimental.UtilityClass;
18-
import org.jsoup.Jsoup;
19-
import org.jsoup.nodes.Element;
20-
import org.jsoup.select.Elements;
2117
import org.openqa.selenium.By;
2218
import solutions.bellatrix.core.configuration.ConfigurationService;
23-
import solutions.bellatrix.core.utilities.HtmlService;
2419
import solutions.bellatrix.core.utilities.InstanceFactory;
2520
import solutions.bellatrix.core.utilities.Ref;
2621
import solutions.bellatrix.core.utilities.Wait;
@@ -32,11 +27,9 @@
3227

3328
import java.time.Duration;
3429
import java.util.ArrayList;
35-
import java.util.Arrays;
3630
import java.util.List;
3731
import java.util.Stack;
3832
import java.util.concurrent.Callable;
39-
import java.util.stream.Collectors;
4033

4134
@UtilityClass
4235
public 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

Comments
 (0)