Windows Test Objects "dissappear" and can't be found again

Two questions…

  1. Is there a “How Stuff Works” doc for Windows Elements and Windows Test Objects? Some sort of internals documentation? I’ve been trying little code samples of every make and model, but I feel like I don’t know what’s going on under the covers, and thats the real problem.

  2. Why isn’t this working? :slight_smile:

I have a Windows app with nesteed tree lists. I have managed to get code that will navitgate down three levels of treelists. It also SUCCESSFULLY does a right-click on the bottom treelist element, chooses an option (“Export”), clicks “Save”, then moves on to the next treelist item.

image
It’s worked for hundreds of entries.

HOWEVER, I need to do two things: the “right-click” above works. But also I need to click on a menu item, choose “Print -> Print to PDF”, and click “Save”.

The steps are virtually identical between the export and the print except one is a right-click, the other is a click. My guess is that the difference is that even though the right-click opens a dialog, it does so WITHIN the context of the main Window. The dialog for the print looks no different, but my sense is that it is a new context.

At any rate, the right-click works again and again. The “click” works one and a half times.

The steps are:

  1. Click on treelist item B.
  2. Tap up-arrow to move focus to the previous item (e.g., treelist item A)
  3. Double-click on the treelist item B (this opens the list of children
  4. findElements to retrieve the children
  5. Click on treelist item B.1… rinse, repeat

THIS PART WORKS.

It works fine for the right click (export), and it works one and half times on the menu click (print).

That is, even after I get a dialog and click save, the program SUCCESSFULLY goes back to the main window, clicks on the next item, expands it if thats where it is, and then tries to print it.

HOWEVER, the second time, it no longer remembers the object it used to start the print process just seconds before.

I have a tried lots of things, like findWindowsObject, findElement, switchWindows, combinations, different orders… nothing.

I would think it was a focus issue, except it REMEMBERS the treelist items, and is able to continue processing the tree AFTER the print.

It just can’t print a second time.

I feel llike I’m missing something. I was careful to preserve the Windows Test Object in the top level scope, and thats what it uses the first time.

Now here’s my suspicion - the thing I’m clicking on… its a button. No text on it. When I look at the Windows Test Object, its miserably empty:

<?xml version="1.0" encoding="UTF-8"?>
<WindowsElementEntity>
   <description></description>
   <name>Menu - External action drop-down menu</name>
   <tag></tag>
   <locator>/Window/Custom[1]/Tab[1]/Menu[1]</locator>
   <locatorStrategy>XPATH</locatorStrategy>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>ElementIndex</name>
      <type>Main</type>
      <value>1</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>RuntimeId</name>
      <type>Main</type>
      <value>7,5620,49997107</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>ItemStatus</name>
      <type>Main</type>
      <value></value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>IsRequiredForForm</name>
      <type>Main</type>
      <value>False</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>FrameworkId</name>
      <type>Main</type>
      <value>WPF</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>Orientation</name>
      <type>Main</type>
      <value>None</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>IsOffscreen</name>
      <type>Main</type>
      <value>False</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>ProcessId</name>
      <type>Main</type>
      <value>5620</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>NativeWindowHandle</name>
      <type>Main</type>
      <value>0</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>ClassName</name>
      <type>Main</type>
      <value>RibbonApplicationMenu</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>ItemType</name>
      <type>Main</type>
      <value></value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>AutomationId</name>
      <type>Main</type>
      <value>appMenu</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>IsContentElement</name>
      <type>Main</type>
      <value>False</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>IsControlElement</name>
      <type>Main</type>
      <value>True</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>HelpText</name>
      <type>Main</type>
      <value>Click here to run various connection-​related commands such as create, save, print and export.</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>BoundingRectangle</name>
      <type>Main</type>
      <value>943,130,56,23</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>IsEnabled</name>
      <type>Main</type>
      <value>True</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>IsKeyboardFocusable</name>
      <type>Main</type>
      <value>True</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>HasKeyboardFocus</name>
      <type>Main</type>
      <value>False</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>AccessKey</name>
      <type>Main</type>
      <value>F</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>AcceleratorKey</name>
      <type>Main</type>
      <value></value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>Name</name>
      <type>Main</type>
      <value></value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>LocalizedControlType</name>
      <type>Main</type>
      <value>menu</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>IsPassword</name>
      <type>Main</type>
      <value>False</value>
   </properties>
   <properties>
      <isSelected>false</isSelected>
      <matchCondition>equals</matchCondition>
      <name>XPath</name>
      <type>Main</type>
      <value>/Window/Custom[1]/Tab[1]/Menu[1]</value>
   </properties>
</WindowsElementEntity>

Here is the code that is repeated one and a half times (with much validation and comments removed)…

WindowsTestObject printMenuTO = findWindowsObject('Export to PDF dialog 2020-01-05/Menu - External action drop-down menu')
for... {
    for... {
        for... {
            experimentNameTO.setLocatorStrategy(WindowsTestObject.LocatorStrategy.NAME)
            experimentNameTO.setLocator(experimentName)
            Windows.findElement(experimentNameTO)
            assert experimentNameTO != null

            'Click treeitem'
            Windows.click(experimentNameTO)

            'Up-arrow'
            Windows.sendKeys(experimentNameTO, Keys.chord(Keys.ARROW_UP))

            'Click treeitem again'
            Windows.click(experimentNameTO)

            'Is it really there?'
            WebElement foundElement = Windows.findElement(printMenuTO)
            assert foundElement != null

            'Click on Print...'
            Windows.click(findWindowsObject('Object Repository/Export to PDF dialog 2020-01-05/MenuItem'))

            'Click on Print as PDF...'
            Windows.click(findWindowsObject('Object Repository/Export to PDF dialog 2020-01-05/MenuItem(1)'))

            'Click "Save" button to confirm Print to PDF action'
            Windows.setText(findWindowsObject('Export to PDF dialog 2020-01-05/Button(1) - Save button in Export to PDF file save dialog'),
                'Save')
        }
    }
}

And here’s the console output:

2021-01-29 14:10:02.458 DEBUG testcase.fullexport2_pdf                 - 8: println("Experiment " + sprintf("%3d", experiment_cnt) + ":  " + notebookName + " : " + experimentName + " - " + experiment.getTagName())
Experiment   1:  Untitled Chemistry Notebook : Untitled Chemistry Notebook-001 - ControlType.TreeItem
2021-01-29 14:10:02.934 DEBUG testcase.fullexport2_pdf                 - 9: outputFile.append(sprintf("%-12s -       %-25s     - %-30s   - %3d - %-30s
", foundProfessor, studentName, notebookName, experiment_cnt, experimentName))
2021-01-29 14:10:02.938 DEBUG testcase.fullexport2_pdf                 - 10: println("Web element:
" + experiment + "
" + experiment.toString())
Web element:
[[[[io.appium.java_client.windows.WindowsDriver, Capabilities: {appTopLevelWindow=3005c0, javascriptEnabled=true, platform=WINDOWS, platformName=WINDOWS}] -> name: Untitled Chemistry Notebook]] -> xpath: */*]
[[[[io.appium.java_client.windows.WindowsDriver, Capabilities: {appTopLevelWindow=3005c0, javascriptEnabled=true, platform=WINDOWS, platformName=WINDOWS}] -> name: Untitled Chemistry Notebook]] -> xpath: */*]
2021-01-29 14:10:02.938 DEBUG testcase.fullexport2_pdf                 - 11: experimentNameTO.setLocatorStrategy(NAME)
2021-01-29 14:10:02.938 DEBUG testcase.fullexport2_pdf                 - 12: experimentNameTO.setLocator(experimentName)
2021-01-29 14:10:02.938 DEBUG testcase.fullexport2_pdf                 - 13: findElement(experimentNameTO)
2021-01-29 14:10:05.424 DEBUG testcase.fullexport2_pdf                 - 14: assert experimentNameTO != null
2021-01-29 14:10:05.426 DEBUG testcase.fullexport2_pdf                 - 15: println("Click on experiment " + experimentNameTO.getLocator())
Click on experiment Untitled Chemistry Notebook-001
2021-01-29 14:10:05.428 DEBUG testcase.fullexport2_pdf                 - 16: click(experimentNameTO)
2021-01-29 14:10:07.686 INFO  c.k.k.c.w.k.helper.WindowsActionHelper   - Clicking on element: null
2021-01-29 14:10:07.931 DEBUG testcase.fullexport2_pdf                 - 17: sendKeys(experimentNameTO, Keys.chord(ARROW_UP))
2021-01-29 14:10:12.285 DEBUG testcase.fullexport2_pdf                 - 18: println("Click on experiment " + experimentNameTO.getLocator())
Click on experiment Untitled Chemistry Notebook-001
2021-01-29 14:10:12.286 DEBUG testcase.fullexport2_pdf                 - 19: click(experimentNameTO)
2021-01-29 14:10:15.063 INFO  c.k.k.c.w.k.helper.WindowsActionHelper   - Clicking on element: null
2021-01-29 14:10:15.866 DEBUG testcase.fullexport2_pdf                 - 20: fileName = sprintf("%s_%s_%s_%s.PDF", professorName, studentName, notebookName, experimentName)
2021-01-29 14:10:15.867 DEBUG testcase.fullexport2_pdf                 - 21: fileName = fileName.replaceAll(",", "")
2021-01-29 14:10:15.871 DEBUG testcase.fullexport2_pdf                 - 22: comment("Place RENAME command in log for " + experimentName)
2021-01-29 14:10:15.876 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Place RENAME command in log for Untitled Chemistry Notebook-001
2021-01-29 14:10:15.876 DEBUG testcase.fullexport2_pdf                 - 23: println("RENAME "" + experimentName + ".PDF" "" + fileName + """)
RENAME "Untitled Chemistry Notebook-001.PDF" "BETLEY_Eames  Emily_Untitled Chemistry Notebook_Untitled Chemistry Notebook-001.PDF"
2021-01-29 14:10:15.877 DEBUG testcase.fullexport2_pdf                 - 24: comment("Set locator strategy for External action menu (print function)")
2021-01-29 14:10:15.879 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Set locator strategy for External action menu (print function)
2021-01-29 14:10:15.879 DEBUG testcase.fullexport2_pdf                 - 25: println("External action menu locator strategy: " + printMenuTO.getLocatorStrategy())
External action menu locator strategy: XPATH
2021-01-29 14:10:15.879 DEBUG testcase.fullexport2_pdf                 - 26: comment("Display locator for External action menu (print function)")
2021-01-29 14:10:15.879 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Display locator for External action menu (print function)
2021-01-29 14:10:15.879 DEBUG testcase.fullexport2_pdf                 - 27: println("External action menu locator: " + printMenuTO.getLocator())
External action menu locator: /Window/Custom[1]/Tab[1]/Menu[1]
2021-01-29 14:10:15.879 DEBUG testcase.fullexport2_pdf                 - 28: comment("Insure the External action menu can be located")
2021-01-29 14:10:15.879 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Insure the External action menu can be located
2021-01-29 14:10:15.879 DEBUG testcase.fullexport2_pdf                 - 29: foundElement = findElement(printMenuTO)
2021-01-29 14:10:27.206 DEBUG testcase.fullexport2_pdf                 - 30: assert foundElement != null
2021-01-29 14:10:27.207 DEBUG testcase.fullexport2_pdf                 - 31: comment("Display foundElement")
2021-01-29 14:10:27.208 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Display foundElement
2021-01-29 14:10:27.214 DEBUG testcase.fullexport2_pdf                 - 32: println("Found element: " + foundElement.toString())
Found element: [[io.appium.java_client.windows.WindowsDriver, Capabilities: {appTopLevelWindow=3005c0, javascriptEnabled=true, platform=WINDOWS, platformName=WINDOWS}] -> xpath: /Window/Custom[1]/Tab[1]/Menu[1]]
2021-01-29 14:10:27.215 DEBUG testcase.fullexport2_pdf                 - 33: comment("Click on external actions dropdown menu at top")
2021-01-29 14:10:27.216 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Click on external actions dropdown menu at top
2021-01-29 14:10:27.216 DEBUG testcase.fullexport2_pdf                 - 34: click(printMenuTO)
2021-01-29 14:10:37.613 INFO  c.k.k.c.w.k.helper.WindowsActionHelper   - Clicking on element: Object Repository/Export to PDF dialog 2020-01-05/Menu - External action drop-down menu
2021-01-29 14:10:37.880 DEBUG testcase.fullexport2_pdf                 - 35: comment("Click on Print...")
2021-01-29 14:10:37.884 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Click on Print...
2021-01-29 14:10:37.885 DEBUG testcase.fullexport2_pdf                 - 36: click(findWindowsObject("Object Repository/Export to PDF dialog 2020-01-05/MenuItem"))
2021-01-29 14:10:47.122 INFO  c.k.k.c.w.k.helper.WindowsActionHelper   - Clicking on element: Object Repository/Export to PDF dialog 2020-01-05/MenuItem
2021-01-29 14:10:47.402 DEBUG testcase.fullexport2_pdf                 - 37: comment("Click on Print as PDF...")
2021-01-29 14:10:47.405 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Click on Print as PDF...
2021-01-29 14:10:47.406 DEBUG testcase.fullexport2_pdf                 - 38: click(findWindowsObject("Object Repository/Export to PDF dialog 2020-01-05/MenuItem(1)"))
2021-01-29 14:10:57.291 INFO  c.k.k.c.w.k.helper.WindowsActionHelper   - Clicking on element: Object Repository/Export to PDF dialog 2020-01-05/MenuItem(1)
2021-01-29 14:10:57.545 DEBUG testcase.fullexport2_pdf                 - 39: comment("Click "Save" button to confirm Print to PDF action")
2021-01-29 14:10:57.546 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Click "Save" button to confirm Print to PDF action
2021-01-29 14:10:57.546 DEBUG testcase.fullexport2_pdf                 - 40: setText(findWindowsObject("Export to PDF dialog 2020-01-05/Button(1) - Save button in Export to PDF file save dialog"), "Save")
2021-01-29 14:11:44.079 DEBUG testcase.fullexport2_pdf                 - 41: comment("Wait 20 seconds for save to complete")
2021-01-29 14:11:44.086 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Wait 20 seconds for save to complete
2021-01-29 14:11:44.087 DEBUG testcase.fullexport2_pdf                 - 42: delay(26)
2021-01-29 14:12:10.091 DEBUG testcase.fullexport2_pdf                 - 43: comment("Reset last_ex_TO")
2021-01-29 14:12:10.095 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Reset last_ex_TO
2021-01-29 14:12:10.095 DEBUG testcase.fullexport2_pdf                 - 44: copyWTO(last_ex_TO, experimentNameTO)
2021-01-29 14:12:10.095 DEBUG testcase.fullexport2_pdf                 - 1: println("toWTO <- fromWTO : " + toWTO.getLocator() + " <- " + fromWTO.getLocator())
toWTO <- fromWTO : Untitled Chemistry Notebook <- Untitled Chemistry Notebook-001
2021-01-29 14:12:10.095 DEBUG testcase.fullexport2_pdf                 - 2: toWTO.setLocatorStrategy(fromWTO.getLocatorStrategy())
2021-01-29 14:12:10.095 DEBUG testcase.fullexport2_pdf                 - 3: toWTO.setLocator(fromWTO.getLocator())
2021-01-29 14:12:10.095 DEBUG testcase.fullexport2_pdf                 - 45: experimentNameOld = experimentName
2021-01-29 14:12:10.095 DEBUG testcase.fullexport2_pdf                 - 46: comment("Exit Loop")
2021-01-29 14:12:10.102 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Exit Loop
2021-01-29 14:12:10.102 DEBUG testcase.fullexport2_pdf                 - 1: if (experiment.getTagName() != "ControlType.TreeItem")
2021-01-29 14:12:10.127 DEBUG testcase.fullexport2_pdf                 - 2: if (experiment.getText() == "Offline")
2021-01-29 14:12:10.168 DEBUG testcase.fullexport2_pdf                 - 3: if (experiment.getText() == "Offline 2")
2021-01-29 14:12:10.199 DEBUG testcase.fullexport2_pdf                 - 4: if (experiment.getText() == "User Configuration")
2021-01-29 14:12:10.233 DEBUG testcase.fullexport2_pdf                 - 5: if (experiment.getText() == "User Configuration 2")
2021-01-29 14:12:10.268 DEBUG testcase.fullexport2_pdf                 - 6: (experiment_cnt++)
2021-01-29 14:12:10.268 DEBUG testcase.fullexport2_pdf                 - 7: experimentName = experiment.getText()
2021-01-29 14:12:10.307 DEBUG testcase.fullexport2_pdf                 - 8: println("Experiment " + sprintf("%3d", experiment_cnt) + ":  " + notebookName + " : " + experimentName + " - " + experiment.getTagName())
Experiment   2:  Untitled Chemistry Notebook : Untitled Chemistry Notebook-002 - ControlType.TreeItem
2021-01-29 14:12:10.347 DEBUG testcase.fullexport2_pdf                 - 9: outputFile.append(sprintf("%-12s -       %-25s     - %-30s   - %3d - %-30s
", foundProfessor, studentName, notebookName, experiment_cnt, experimentName))
2021-01-29 14:12:10.349 DEBUG testcase.fullexport2_pdf                 - 10: println("Web element:
" + experiment + "
" + experiment.toString())
Web element:
[[[[io.appium.java_client.windows.WindowsDriver, Capabilities: {appTopLevelWindow=3005c0, javascriptEnabled=true, platform=WINDOWS, platformName=WINDOWS}] -> name: Untitled Chemistry Notebook]] -> xpath: */*]
[[[[io.appium.java_client.windows.WindowsDriver, Capabilities: {appTopLevelWindow=3005c0, javascriptEnabled=true, platform=WINDOWS, platformName=WINDOWS}] -> name: Untitled Chemistry Notebook]] -> xpath: */*]
2021-01-29 14:12:10.349 DEBUG testcase.fullexport2_pdf                 - 11: experimentNameTO.setLocatorStrategy(NAME)
2021-01-29 14:12:10.349 DEBUG testcase.fullexport2_pdf                 - 12: experimentNameTO.setLocator(experimentName)
2021-01-29 14:12:10.349 DEBUG testcase.fullexport2_pdf                 - 13: findElement(experimentNameTO)
2021-01-29 14:12:12.139 DEBUG testcase.fullexport2_pdf                 - 14: assert experimentNameTO != null
2021-01-29 14:12:12.140 DEBUG testcase.fullexport2_pdf                 - 15: println("Click on experiment " + experimentNameTO.getLocator())
Click on experiment Untitled Chemistry Notebook-002
2021-01-29 14:12:12.142 DEBUG testcase.fullexport2_pdf                 - 16: click(experimentNameTO)
2021-01-29 14:12:13.756 INFO  c.k.k.c.w.k.helper.WindowsActionHelper   - Clicking on element: null
2021-01-29 14:12:14.066 DEBUG testcase.fullexport2_pdf                 - 17: sendKeys(experimentNameTO, Keys.chord(ARROW_UP))
2021-01-29 14:12:19.381 DEBUG testcase.fullexport2_pdf                 - 18: println("Click on experiment " + experimentNameTO.getLocator())
Click on experiment Untitled Chemistry Notebook-002
2021-01-29 14:12:19.382 DEBUG testcase.fullexport2_pdf                 - 19: click(experimentNameTO)
2021-01-29 14:12:22.002 INFO  c.k.k.c.w.k.helper.WindowsActionHelper   - Clicking on element: null
2021-01-29 14:12:22.824 DEBUG testcase.fullexport2_pdf                 - 20: fileName = sprintf("%s_%s_%s_%s.PDF", professorName, studentName, notebookName, experimentName)
2021-01-29 14:12:22.825 DEBUG testcase.fullexport2_pdf                 - 21: fileName = fileName.replaceAll(",", "")
2021-01-29 14:12:22.826 DEBUG testcase.fullexport2_pdf                 - 22: comment("Place RENAME command in log for " + experimentName)
2021-01-29 14:12:22.830 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Place RENAME command in log for Untitled Chemistry Notebook-002
2021-01-29 14:12:22.831 DEBUG testcase.fullexport2_pdf                 - 23: println("RENAME "" + experimentName + ".PDF" "" + fileName + """)
RENAME "Untitled Chemistry Notebook-002.PDF" "BETLEY_Eames  Emily_Untitled Chemistry Notebook_Untitled Chemistry Notebook-002.PDF"
2021-01-29 14:12:22.832 DEBUG testcase.fullexport2_pdf                 - 24: comment("Set locator strategy for External action menu (print function)")
2021-01-29 14:12:22.834 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Set locator strategy for External action menu (print function)
2021-01-29 14:12:22.835 DEBUG testcase.fullexport2_pdf                 - 25: println("External action menu locator strategy: " + printMenuTO.getLocatorStrategy())
External action menu locator strategy: XPATH
2021-01-29 14:12:22.836 DEBUG testcase.fullexport2_pdf                 - 26: comment("Display locator for External action menu (print function)")
2021-01-29 14:12:22.838 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Display locator for External action menu (print function)
2021-01-29 14:12:22.838 DEBUG testcase.fullexport2_pdf                 - 27: println("External action menu locator: " + printMenuTO.getLocator())
External action menu locator: /Window/Custom[1]/Tab[1]/Menu[1]
2021-01-29 14:12:22.839 DEBUG testcase.fullexport2_pdf                 - 28: comment("Insure the External action menu can be located")
2021-01-29 14:12:22.841 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - Insure the External action menu can be located
2021-01-29 14:12:22.842 DEBUG testcase.fullexport2_pdf                 - 29: foundElement = findElement(printMenuTO)
2021-01-29 14:13:23.900 ERROR c.k.k.core.keyword.internal.KeywordMain  - ❌ Expected condition failed: waiting for com.kms.katalon.core.windows.keyword.helper.WindowsActionHelper$1@4aa11206 (tried for 60 second(s) with 50 milliseconds interval) (Root cause: org.openqa.selenium.TimeoutException: Expected condition failed: waiting for com.kms.katalon.core.windows.keyword.helper.WindowsActionHelper$1@4aa11206 (tried for 60 second(s) with 50 milliseconds interval)
    at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:304)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
    at com.kms.katalon.core.windows.keyword.helper.WindowsActionHelper.findElement(WindowsActionHelper.java:120)
    at com.kms.katalon.core.windows.keyword.helper.WindowsActionHelper.findElement(WindowsActionHelper.java:77)
    at com.kms.katalon.core.windows.keyword.helper.WindowsActionHelper.findElement(WindowsActionHelper.java:69)
    at com.kms.katalon.core.windows.keyword.helper.WindowsActionHelper$findElement$1.call(Unknown Source)
    at com.kms.katalon.core.windows.keyword.builtin.FindElementKeyword$_findElement_closure1.doCall(FindElementKeyword.groovy:47)
    at com.kms.katalon.core.windows.keyword.builtin.FindElementKeyword$_findElement_closure1.doCall(FindElementKeyword.groovy)
    at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:77)
    at com.kms.katalon.core.keyword.internal.KeywordMain$runKeyword.call(Unknown Source)
    at com.kms.katalon.core.windows.keyword.builtin.FindElementKeyword.findElement(FindElementKeyword.groovy:37)
    at com.kms.katalon.core.windows.keyword.builtin.FindElementKeyword$findElement.callCurrent(Unknown Source)
    at com.kms.katalon.core.windows.keyword.builtin.FindElementKeyword.execute(FindElementKeyword.groovy:32)
    at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)
    at com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords.findElement(WindowsBuiltinKeywords.java:718)
    at com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords$findElement$3.call(Unknown Source)
    at fullexport2_pdf.run(fullexport2_pdf:458)

Note that I tried to use this:

        'Insure focus goes to correct Window'
        Windows.switchToWindow(experimentNameTO)

That’s the object I am successfully able to click on. However that switch statement returned the message:

Unable to create a new remote session.

There was another post in the forum for that message, but in the mobile section. I keep going back to “I don’t need to switch windows because I am already successfully clicking in the one I need to use”. Also, that thread dried up last March with no conclusion.

So, back to my original question, I can’t understand why I can’t reuse a Windows Test Object (well, I do understand - as the self repairing docs say, these objects are fragile). But it seems to dissappear without a trace, and I can’t figure out a way to find it again!

ANY and ALL suggestions, no matter how obvious they may seem to you, are welcome.

Thanks!

Jim

Oh… FYI the “foundElement” was one of the things I tried. If that isn’t there, then the next statement is the click, which fails with the same message: timeout/not found.

One more quick update - I dumped out the contents of the WTO before and after it failed, and the object is still there, and the properties are unchanged.

Its just that the object the WTO refers to CANNOT be found the second time I execute the same code.

I’m going to try using coordinates instead, which are there the first time through, but I have to upgrade to 7.8.

I JUST DON’T GET IT!!!

Why does the code work perfectly the first time through (and EVERY time through when doing a right-click) but never again?

I get that test objects are fragile. But this works fine when I right click on an element. It opens a dialog, writes a file, and then moves on.

I used the EXACT SAME CODE but instead of a right-click, I click on the print menu.

It works the first time, and then I continue moving down the list to print the next item, which works just fine and then times out whether I “click”, “clickElementOffset”, or findElement.

I upgraded to Katalon 7.9, because the version I was running didn’t have support for the clickElementOffset capability.

Unfortunately I have the exact same results…

  1. Click on the next treelist item (always works)
  2. Use element offset to click on the “print” menu
  3. Click the various parts of the print menu to export the PDF
  4. Repeat

The first time, both clicking on the WTO and clicking by element offset both work.

After I click the next item on the page, findWindowsObject still works, but neither “click”, clickElementOffset nor findElement works. It times out.

Why can I access everything else on the page, like tabs, treeitems, and even perform right clicks successfully over and over, but this one menu item dissappears never to be seen again?

Here’s the code again with some annotations:

        'Click on treelistItem to export'
        Windows.click(experimentNameTO)

		printMenuTO = findWindowsObject('Export to PDF dialog 2020-01-05/Menu - External action drop-down menu')
        
        /* THIS STATEMENT WILL WORK THE FIRST TIME, BUT NEVER AGAIN SO I TOOK IT OUT */
		//Windows.findElement(printMenuTO)                              // Works once but fails after first pass

        Windows.delay(20)

        /* Since findElement only works once, I lamely tried to capture the information
         * from the windowsElement the first time through, and reuse it on subsequent passes,
         * since the print menu that I successfully click the first time doesn't move,
         * but for some reason can't be found on subsequent passes
         */
        if ( foundElement == null ) {
            // First time through, foundElement is null, but printMenuTO should not be
            foundElement = Windows.findElement(printMenuTO)
            if( xCoord == -1) {
                xCoord = foundElement.location.x + 5
                yCoord = foundElement.location.y - 10
            }
        }
        
        /* Using "click" works the first time, but never again, so I upgraded Katalon 
         * and tried "clickElementOffset" instead of "click"
        */
        //Windows.click(printMenuTO)                                    // Works once but fails after first pass
        println "Clicking on X = " + xCoord + ", Y = " + yCoord
        Windows.clickElementOffset(printMenuTO, xCoord, yCoord)         // Works once but fails after first pass

        // NEVER GETS HERE THE SECOND TIME

        'Click on Print menu item...'
        Windows.click(findWindowsObject('Object Repository/Export to PDF dialog 2020-01-05/MenuItem'))

        'Click on Print as PDF... menu item'
        Windows.click(findWindowsObject('Object Repository/Export to PDF dialog 2020-01-05/MenuItem(1)'))

        'Click "Save" button to confirm Print to PDF action'
        Windows.setText(findWindowsObject('Export to PDF dialog 2020-01-05/Button(1) - Save button in Export to PDF file save dialog'), 'Save')

        'Wait 26 seconds for save to complete'
        Windows.delay(26)

Here is the dump of everything I found in the Windows Test Object:

printMenuTO_2021-01-30-20-55-29.txt
==================================================================================================================
printMenuTO.objectId: (from Object Repository)'Object Repository/Export to PDF dialog 2020-01-05/Menu - External action drop-down menu'
------------------------------------------------------------------------------------------------------------------
printMenuTO.toString()
com.kms.katalon.core.testobject.WindowsTestObject@7ff8a9dc
------------------------------------------------------------------------------------------------------------------
printMenuTO.locatorStrategy: 'XPATH'
printMenuTO.locatorStrategy: '/Window/Custom[1]/Tab[1]/Menu[1]'
printMenuTO.objectId:        'Object Repository/Export to PDF dialog 2020-01-05/Menu - External action drop-down menu'
printMenuTO.hashCode():      '2147002844'
printMenuTO.class:           'class com.kms.katalon.core.testobject.WindowsTestObject'
------------------------------------------------------------------------------------------------------------------
printMenuTO property name: ElementIndex                  '1'
printMenuTO property name: RuntimeId                     '7,5620,49997107'
printMenuTO property name: ItemStatus                    ''
printMenuTO property name: IsRequiredForForm             'False'
printMenuTO property name: FrameworkId                   'WPF'
printMenuTO property name: Orientation                   'None'
printMenuTO property name: IsOffscreen                   'False'
printMenuTO property name: ProcessId                     '5620'
printMenuTO property name: NativeWindowHandle            '0'
printMenuTO property name: ClassName                     'RibbonApplicationMenu'
printMenuTO property name: ItemType                      ''
printMenuTO property name: AutomationId                  'appMenu'
printMenuTO property name: IsContentElement              'False'
printMenuTO property name: IsControlElement              'True'
printMenuTO property name: HelpText                      'Click here to run various connection-ΓÇïrelated commands such as create, save, print and export.'
printMenuTO property name: BoundingRectangle             '943,130,56,23'
printMenuTO property name: IsEnabled                     'True'
printMenuTO property name: IsKeyboardFocusable           'True'
printMenuTO property name: HasKeyboardFocus              'False'
printMenuTO property name: AccessKey                     'F'
printMenuTO property name: AcceleratorKey                ''
printMenuTO property name: Name                          ''
printMenuTO property name: LocalizedControlType          'menu'
printMenuTO property name: IsPassword                    'False'
printMenuTO property name: XPath                         '/Window/Custom[1]/Tab[1]/Menu[1]'
==================================================================================================================

And here is what the WebElement looks like on the first pass:

WebElement name:        foundElement
-------------------------------------------------
WebElement location:    (8, 31)
WebElement rect:        <unsupported>
WebElement size:        (56, 23)
WebElement tagName:     ControlType.Menu
WebElement text:        
WebElement isDisplayed: true
WebElement isEnabled:   true
WebElement isSelected:  false

Okay, one last desparate plea for help.

This project is being shut down at the end of today. It was a partial success, because I was able to navigate the treelist, right click on each one, and trigger the XML export.

I have been unable to access the print menu and print a PDF more than once.

The first time works fine, it moves to the next item as it does doing XML, but it times out looking for the print menu.

I understand the fragility, though I really don’t understand the underlying cause. If I had to guess, I’d say that the Windows Test Objects I recorded originally become invalid or something at some point,

But out of curiousity, I tried the following…

Early on, just to make sure everything was behaving, I included code that clicks on the title bar of the Window, then clicks on a couple of tabs that are adjacent to the print menu:

image

I click on the title bar then “Data”, then “Home”.

Here’s how it looks the first time…

image

I copied that code and put it right in front of where I access the print menu (circled above). I figured if I could hit the “home” tab again, I might be able to hit the print menu, and perhaps clicking the title bar, etc. would help it “remember” what it successfully did seconds earlier.

I even had a brilliant idea that even if it still couldn’t find the print menu, perhaps I could click on the “home” tab with a negative X offset, and hit the print menu instead.

It was not to be.

After the successful first pass, it was able to once again find the title bar, EVEN THOUGH the text in the title bat had changed! So at the very least, the Windows Test Objet for the title bar, even when its text changes, is still correct (the XPath still works).

But then the dreaded timeout waiting to click on the “data” tab.

I JUST DON’T UNDERSTAND IT.

I can access EVERYTHING in the app over and over again, and I can even access the essential print menu successfully ONCE.

But after that, even though everything else seems completely accessible, the print menu cannot be found.

I fully accept that there is probably something bizarre going on inside the Windows application itself, but it just doesn’t make sense that everything works fine except the one thing I need!

I am really desperate here, and don’t have much time.

ANY idea, no matter how bizzare is welcome.

Thanks.

How “rapid” do you go from one test cycle to the next? Do you try to do two in a day and the second one does not work, or do you try to do one on one day and then the second one on a second day? Basically, how much gap between each test? (could a queue be in-use or full; even some type of lock)

Its rapid. I think you are referring to an integration test cycle. This is actually running against a production system, and there is no test suite - its just these two scripts, one to export treelist items as XML, and one to export PDF. In another post I think I explained that this product has an arcane internal format, and no bulk export. The desire is to retire the product, but capture all the data from it in XML and PDF formats first.

So basically it runs one after another, limited on ly really by Katalon’s speed, which for some of the find objects can be quite slow.

I did add some 20 second delays in between some of the operations in case the GUI (or even Katalon and the Windows Application Driver) needed to “settle”.

The two data points that address queuing are (a) the code that navigates the treelist is the exact code used to do the XML export. The XML phase successfully nevigated hundreds of XML exports successfully in a single run.

And (b) I can manually take mouse in hand and perform the PDF exports as quickly as my nimble fingers (and the server) can go.

And I can run the program over and over, once after another, and the XML works flawlessly, and the PDF always works on the first entry it attempts to export.

An XML export (right-click menu) takes a few seconds. A PDF export does a mess of rendering in the background, displays a status bar, and takes as much as 20 seconds (probably longer for bigger exports - I bumped from 20 to 26 seconds for the cases that succeeded).

Also, the runs are being done “manually”, as in I log into the test machine, open Katalon, and click on the green “go” button, and in this phase of the project I do that dozens of times a day.

I’ve also manually clicked on the print menu button immediately after a run, or sometimes DURING a run, and it responds normally.

There’s no indication that the application itself is misbehaving. Katalon knows going in where the print menu is, it just is never able to find it twice, even though it seems to find many other screen elements without a problem, both before and after.

Good question, though. I’m VERY familiar with this thing’s operation now since I’ve been working on this for months, so its easy to skip over details.

Jim