Forum Discussion

cruzader's avatar
cruzader
Contributor
13 years ago

Cannot access specific objects in Devices and Printers

Hello to all,



I would like to ask for assistance from those very knowledgeable in TC8.



I wanted to create a script that would access objects in Devices and Printers window of Windows 7.

Specifically, I'm trying to find a specific printer (Ex. Printer1 is the name of the printer), then perform a right-click action while Printer1 is currently selected.  The when the context menu is displayed, I wanted to click the Printer Properties menu.



The problem I'm having is that, I cannot seem to access specific items inside the list of the Devices and Printers.

When I tried recording the steps I wanted, the generated scripts uses coordinates.  As much as possible, I don't want to use coordinates in performing clicks or accessing objects.



Thanks in advance for those who could share their expertise on this.



Regards,

Ruel
  • What are you trying to test by accessing the printer properties?  Is this something that can be done by instantiating something within the windows environment?
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    What are you trying to test by accessing the printer properties?  Is this something that can be done by instantiating something within the windows environment?
  • Hi Ruel,



    Try using the following code (machinename is the name of the computer where the needed printer is located):

    Dim WshShell, oExec


    Set WshShell = CreateObject("WScript.Shell")


    Set oExec = WshShell.Exec("rundll32 printui.dll,PrintUIEntry /p /n\\machinename\Printer1")


  • Hi Ruel,



    According to the information you sent to me, you can try using the following modified code:

    Dim WshShell, oExec, prnName
     

    prnName ="PathToPrinter"  'specify the path to the needed printer, for example, \\machinename\Printer1


    Set WshShell = CreateObject("WScript.Shell")


    Set oExec = WshShell.Exec("rundll32 printui.dll,PrintUIEntry /p /n" & prnName)




    Also, you can modify the command line (the parameter of WshShell.Exec) as you need - run printUI.exe in the command prompt to get the list of available switches and examples.

  • Hi Ruel,



    It is not clear for what you need to work with a graphic user interface instead of using a command line. However, to be able to access items of the Devices and Printers window, add DirectUIHWND to 'List of accepted windows' in the MSAA options of your project properties.







  • Oferv's avatar
    Oferv
    Super Contributor
    Hi All,



    How to i convert this vbscript code to work on c#script?



    Thanks
  • By the way, I forgot to mention that I'm using VBScript in my TC8.

    Thanks!
  • Hello Robert and David,



    Thank you for replying to my post.



    Posted by Robert Martin [TeamAQA] on 11/2/2011 9:19:16 AM

    What are you trying to test by accessing the printer properties?  Is
    this something that can be done by instantiating something within the
    windows environment?




    >> I need to visually open the Printer Properties and Printing Preferences of dynamically installed printer drivers in my test PC.

    The tests I need to do involves changing different settings of the printer drivers.  And for me to do that, I need to be able to select the correct printer driver from the Devices and Printers window by using their actual printer names and not just by coordinates since the installed printer drivers may be dynamic.  I cannot seem to access device items inside the Devices and Printers window of Windows 7.



    I hope you could still provide some help.

    Thank you very much.
  • Hello David,



    Thanks for the code.

    However, the method you presented by-passes the procedure needed (opening the Printing Preferences from context menu of the Printer Driver).

    Is it because TC is not really able to access the items listed in the Devices and Printers window of Windows 7?



    I hope there could be a way to simulate actual opening of Printing Preferences of printer drivers using the mouse (but not using coordinates).

    Thanks for the help.



    Regards,

    Ruel
  • Hello David,



    To give you a picture on why I need accessing the Devices and Printers through GUI and not through command line is that,

    I have already used TestComplete versions 6 and 7 in the previous company I worked for.  Now, in the company I'm currently working at has not yet invested in Automation tools.  All their testing is done manually.  My bosses are still hesitant on purchasing expensive tools that's why I'm creating scripts to be used for demo and present to them that TestComplete is able to do automatically the exact testing procedures that they were doing manually before.  Although I know that the method you provided was indeed correct and faster, for the purpose that my bosses can understand what automation is all about, I wanted to present the same steps that they were used to doing but now, automatically using the TestComplete tool.  I hope you understand my predicament.



    BTW, your suggestion on including the DirectUIHWND in the list of accepted windows already worked.

    Thank you very much for the help.



    Regards,

    Ruel