Can SilkTest click on a window it cannot recognise? (Low level approach solution)
SilkTest can have difficulty recognising customised applications (Customised Components). If there is a window that SilkTest cannot recognise and you require to click a button on it to continue your test, this technique could solve your problem.
Using the user32.dll we can obtain the window identifier for the foreground window. We can then move the window to a designated position on the screen and click the button using relative coordinates to the main window.
The script below has been written for the test application (All Programs | SilkTest | Sample Applications | TestApp.exe)
The first part of the script selects the menu item Menu | The Item
And clicks the OK button using window identifiers and tags recorded by SilkTest
The second part of the script selects the menu item Menu | The Item as before, but moves the message box to the screen position 0,0 and clicks the mouse at a position relative to the main window. This is achieved by finding the windows identifier for the foreground window(GetForegroundWindow()), moving this window to the screen position 0,0 (MoveWindow( )) and using the main window to click a position on the screen relative to it (TestApplication1.click(1,100,60)).
[-] dll "user32.dll" [ ] LONG GetForegroundWindow() [ ] Long MoveWindow(Long hWnd,long X,long Y,long nWidth,long nHeight,long bRepaint) [ ] [ ] [-] testcase test1() [ ] LONG lWinID,lresult [ ] [ ] TestApplication.SetActive () [ ] TestApplication.Maximize () [ ] TestApplication.Menu.TheItem.Pick () [ ] //set the dialog box active [ ] TestApplication1.SetActive () [ ] //click the object using the object name [ ] TestApplication1.OK.Click () [ ] [ ] Sleep(3) [ ] [ ] TestApplication.SetActive () [ ] TestApplication.Menu.TheItem.Pick () [ ] [ ] //find the window identifier for the foreground window [ ] lWinID=GetForegroundWindow() [ ] Sleep(2) [ ] //Move the window to the top of the screen coordinate 0,0 [ ] lresult= MoveWindow(lWinID,0,0,250,120,1) [ ] Sleep(3) [ ] //using the main window, click relative to it [ ] TestApplication1.SetActive () [ ] //TestApplication1.click() [ ] TestApplication1.click(1,100,60) [ ] Sleep(3)