cancel
Showing results for 
Search instead for 
Did you mean: 

python exception on ClickItem() not caught

SOLVED
Highlighted
Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
Contributor

Re: python exception on ClickItem() not caught

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)
      break 

 

But in selenium try/except catches everything, must easier with exception handling.

View solution in original post

3 REPLIES 3
Community Hero

Re: python exception on ClickItem() not caught

Hi,

 

> it always fails.

More details as for your definition of 'fails', please? Error message from the test log if exists.

 

> app.MainWindow.[...].ComboboxOperatorCardReader.ClickItem(...)

As long as the ComboboxOperatorCardReader object exists and is of combo-box type (or any other object type that provides .ClickItem() method) no exception is expected here.

Exception is a critical failure of the code been executed. In your case, code can be executed without failure. But the certain item might not exists and thus cannot be clicked. In this case you will get an error in the test log, but this is not a reason for exception throwing.

What you need to do is check first if the required item to be clicked exists and proceed appropriately.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Contributor

Re: python exception on ClickItem() not caught

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)
      break 

 

But in selenium try/except catches everything, must easier with exception handling.

View solution in original post

Community Hero

Re: python exception on ClickItem() not caught

Hi,

 

Thank you for the update and it is good to know that the problem is solved.

 

in selenium try/except catches everything

Selenium (like any other assertion-based library with atomic verifications) architecturally is designed around exceptions and throws exceptions on every failed line of code. Then one has two options: either handle possible expected exceptions (and do not see a problem unless carefully reading test log for details) or have failed test and the necessity to fix it and re-run.

TestComplete, on the contrary, does not throw exceptions on failed actions over UI elements but instead posts a relevant (and clearly visible) message to the test log. What happens next depends on the test project settings: test may be aborted or continued. For some non-critical problems with access to UI elements in a long-playing tests the latter setting gives a chance to end the test and get result that can be reported (in an urgent situations). And then the test may be corrected and executed a-new.

Also, possibility to continue is quite useful during test development.

 

Just my $0.02 Smiley Happy

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
New Here?
Join us and watch the welcome video:
Watch the new Interview