@@ -174,6 +174,10 @@ def _take_selection(element: xa11y.Element) -> str:
174174 return ""
175175
176176
177+ def _take_selection_matches (element : xa11y .Element | None , * , selection : str ) -> bool :
178+ return element is not None and _take_selection (element ) == selection
179+
180+
177181def _take_combo_index (elements : list [xa11y .Element ]) -> int :
178182 """Return the one-based index of the visible Takes combo box."""
179183 visible = [
@@ -222,18 +226,49 @@ def _activate_take_option(option: xa11y.Locator, selection: str) -> None:
222226 xa11y .input_sim ().click (option_element )
223227
224228
225- def _wait_for_take_selection (combo : xa11y .Locator , selection : str ) -> None :
226- """Confirm a highlighted Qt combo row when activation did not commit it."""
229+ def _open_take_combo (combo : xa11y .Locator ) -> None :
230+ combo_actions = set (combo .element ().actions )
231+ if "show_menu" in combo_actions :
232+ combo .show_menu ()
233+ elif "expand" in combo_actions :
234+ combo .expand ()
235+ else :
236+ combo .press ()
237+
238+
239+ def _take_option (combo : xa11y .Locator , selection : str ) -> xa11y .Locator :
240+ option_selector = (
241+ f"list_item[name='{ selection } '], "
242+ f"table_row[name='{ selection } '], "
243+ f"static_text[name='{ selection } ']"
244+ )
245+ option = combo .descendant (option_selector ).first ()
246+ try :
247+ option .wait_visible (timeout = 3.0 )
248+ except xa11y .TimeoutError :
249+ pid = combo .element ().pid
250+ if pid is None :
251+ raise AssertionError ("Take combo does not expose its application PID" ) from None
252+ option = xa11y .App .by_pid (pid ).locator (option_selector ).first ()
253+ option .wait_visible (timeout = 10.0 )
254+ return option
227255
228- def is_selected (element ):
229- return element is not None and _take_selection (element ) == selection
230256
257+ def _wait_for_take_selection (combo : xa11y .Locator , selection : str ) -> None :
258+ """Confirm a highlighted Qt combo row when activation did not commit it."""
231259 try :
232- combo .wait_until (is_selected , timeout = 1.0 )
260+ combo .wait_until (
261+ partial (_take_selection_matches , selection = selection ),
262+ timeout = 1.0 ,
263+ )
233264 return
234265 except xa11y .TimeoutError :
235- xa11y .input_sim ().press ("Enter" )
236- combo .wait_until (is_selected , timeout = 10.0 )
266+ pass
267+ xa11y .input_sim ().press ("Enter" )
268+ combo .wait_until (
269+ partial (_take_selection_matches , selection = selection ),
270+ timeout = 10.0 ,
271+ )
237272
238273
239274def _job_specific_text_field (dialog : xa11y .Locator , nth : int ) -> xa11y .Locator :
@@ -343,28 +378,9 @@ def select_takes(dialog: xa11y.Locator, selection: str) -> None:
343378 if current == selection :
344379 return
345380
346- combo_actions = set (combo .element ().actions )
347- if "show_menu" in combo_actions :
348- combo .show_menu ()
349- elif "expand" in combo_actions :
350- combo .expand ()
351- else :
352- combo .press ()
381+ _open_take_combo (combo )
353382
354- option_selector = (
355- f"list_item[name='{ selection } '], "
356- f"table_row[name='{ selection } '], "
357- f"static_text[name='{ selection } ']"
358- )
359- option = combo .descendant (option_selector ).first ()
360- try :
361- option .wait_visible (timeout = 3.0 )
362- except xa11y .TimeoutError :
363- pid = combo .element ().pid
364- if pid is None :
365- raise AssertionError ("Take combo does not expose its application PID" ) from None
366- option = xa11y .App .by_pid (pid ).locator (option_selector ).first ()
367- option .wait_visible (timeout = 10.0 )
383+ option = _take_option (combo , selection )
368384
369385 _activate_take_option (option , selection )
370386 _wait_for_take_selection (combo , selection )
0 commit comments