@@ -154,17 +154,37 @@ def shadow_root_elements(shadow_root_ds: list[list[str]], element_ds: list[list[
154
154
# Traverse each shadow root level
155
155
for idx , shadow_param in shadow_root_params :
156
156
shadow_host_query = None
157
+ locator_type = None
157
158
for idx2 , parent_param in parent_params :
158
159
if idx == idx2 :
159
- shadow_host_query = build_css_selector_query ([parent_param , shadow_param ])
160
+ if idx == 1 :
161
+ shadow_host_query , query_type = _construct_query ([parent_param , shadow_param ])
162
+ locator_type = By .XPATH if query_type == "xpath" else By .CSS_SELECTOR
163
+ else :
164
+ shadow_host_query = build_css_selector_query ([parent_param , shadow_param ])
160
165
break
161
166
162
167
# Build CSS selector for the current shadow host
163
168
if not shadow_host_query :
164
- shadow_host_query = build_css_selector_query ([shadow_param ])
169
+ if idx == 1 : # First shadow root without parent, use XPath
170
+ shadow_host_query , query_type = _construct_query ([shadow_param ])
171
+ locator_type = By .XPATH if query_type == "xpath" else By .CSS_SELECTOR
172
+ else :
173
+ shadow_host_query = build_css_selector_query ([shadow_param ])
174
+ locator_type = By .CSS_SELECTOR
165
175
shadow_host_index = _locate_index_number ([shadow_param ]) or 0
166
176
167
- elements = current_root .find_elements (By .CSS_SELECTOR , shadow_host_query )
177
+ CommonUtil .ExecLog (
178
+ sModuleInfo ,
179
+ f"To locate the Element we used { locator_type } :\n { shadow_host_query } " ,
180
+ 5
181
+ )
182
+
183
+ elements = None
184
+ if locator_type == By .XPATH :
185
+ elements = current_root .find_elements (By .XPATH , shadow_host_query )
186
+ else :
187
+ elements = current_root .find_elements (By .CSS_SELECTOR , shadow_host_query )
168
188
169
189
filtered_elements = filter_elements (elements , Filter )
170
190
if not filtered_elements :
@@ -549,7 +569,7 @@ def _construct_query(step_data_set, web_element_object=False):
549
569
and driver_type in ("appium" , "selenium" )
550
570
): # for unique identifier
551
571
return [unique_parameter_list [0 ][0 ], unique_parameter_list [0 ][2 ]], "unique"
552
- elif "css " in collect_all_attribute and "xpath" not in collect_all_attribute :
572
+ elif "css_selector " in collect_all_attribute and "xpath" not in collect_all_attribute :
553
573
# return the raw css command with css as type. We do this so that even if user enters other data, we will ignore them.
554
574
# here we expect to get raw css query
555
575
return ([x for x in step_data_set if "css" in x [0 ]][0 ][2 ]), "css"
0 commit comments