mortenb123
7 years agoContributor
python exception on ClickItem() not caught
I have some usb smartcards that switches adressing based on windows discovery, so they can show up ending with either 0 or 1, but I'm unable to catch when the clickitem() does not exists, it always fails.
for reader in ["Gemalto USB Smart Card Reader {n}", "Gemalto IDBridge CT7xx {n}"]:
for n in range(2):
myreader = reader.format(n=n)
try:
app.MainWindow.TabControl2.TabControlConfig.ItemsControl.ComboboxOperatorCardReader.ClickItem(myreader)
except Exceptions as e:
if n>=1:
Log.Error(f"{e}")
continue
else:
Log.Message(f"found {myreader}")
break
Thanks
Just to follow up. I rewrote the test to use dropdown and choose that is fetched:
#Selects the 'Gemalto USB Smart Card Reader 1' item of the 'ComboboxOperatorCardReader' combo box. reader = "Gemalto USB Smart Card Reader" app.MainWindow.TabControl2.TabControlConfig.ItemsControl.ComboboxOperatorCardReader.Click() ComboBox = app.MainWindow.TabControl2.TabControlConfig.ItemsControl.ComboboxOperatorCardReader for i in range(ComboBox.wItemCount): Item = aqString.GetListItem(ComboBox.wItemList, i) if reader in Item: Log.Message(f"found {Item}") app.MainWindow.TabControl2.TabControlConfig.ItemsControl.ComboboxOperatorCardReader.ClickItem(Item) break reader = "Gemalto IDBridge CT7xx" ComboBox = app.MainWindow.TabControl2.TabControlConfig.ItemsControl.ComboboxOperatorCardReader # focus object missing name, Accessibility Insight gives error ComboBox.Click(335, 13) Sys.Keys("[Tab]") for i in range(ComboBox.wItemCount): Item = aqString.GetListItem(ComboBox.wItemList, i) if reader in Item: Log.Message(f"found {Item}") app.MainWindow.TabControl2.TabControlConfig.ItemsControl.ComboboxOperatorCardReader.ClickItem(Item) breakBut in selenium try/except catches everything, must easier with exception handling.