Jump to content

Recommended Posts

Posted

Hello All,

 

I have a script I'm trying to fix. I've gone through the IE functions and I'm trying to fix them to allow the script to get up and running again.

I'm currently on the _WD_FindElement function and I'm not sure if I'm modifying this correctly.

A question I have is, what is the correct syntax for this function?

Syntax ........: _WD_FindElement($sSession, $sStrategy, $sSelector[, $sStartNodeID = Default[, $bMultiple = Default[,

$oImgs_checkbox = _WD_FindElement($oIE, , , True, "imgChkBox")

What this is trying to do is record the count of how many checkboxes there are. Then check them. I think it put's them all into an array and then checks  them. 

 

Originally the checkboxes on the page were called "Img" I think they may be "imgChkBox" when I viewed page source that is the name that was displayed. The Autoit Window tool did not locate the items. Maybe I have an issue with the window tool? When I also go into calculator it does not find the buttons in windows calculator.

 

Also if anyone has any alternative methods/ideas to automate something like this I would love to hear!

;----------------------------------------------------------------------------------------------------------------------------------------------
Func BrowserControlFocus()
; Set focus on the Browser control - write which page is being tested and the location of the file.
; Output the name and location of the html page being tested.
sleep(5000)
$hWnd=WinGetHandle("[CLASS:Chrome_RenderWidgetHostHWND; INSTANCE:1]")
$oIE = _WD_Attach($hWnd,"embedded")
_WD_LoadWait($oIE)
WriteToFile($outputFile,"The displayed page is the: " &_WD_Action($oIE, "title") & " page")
WriteToFile($outputFile,"File Location is: " & _WD_Action($oIE, "locationurl"))
EndFunc
;_IEPropertyGet ( ByRef $oObject, $sProperty )
;
;$oObject   Object variable of an InternetExplorer.Application or DOM element
;$sProperty Property selection (see remarks)
;WriteToFile($outputFile,"The displayed page is the: " & _WD_Action($sSession, 'title') & " page")
;WriteToFile($outputFile,"File Location is: " & _WD_Action($sSession, 'url'))
;
;
;
;
;----------------------------------------------------------------------------------------------------------------------------------------------

;Find all the instances of the checkbox, put the ID name of the checkbox image into an array.  ID name is hard coded in the
; THis rountine is specific to the ID name in the HTML file.  If the name changes then this routine will break.  The checkbox id is
; XXi where xx is a number value

Func CheckBoxID()
_WD_LoadWait($oIE)
Global $Checkbox_count = -1
$oImgs_checkbox = _WD_FindElement($oIE, , , True, "imgChkBox")
$ClearChecksStr = "ClearChecks Button"

; Count the number of checkboxes and put the id number in an array
For $oImg_Checkbox in $oImgs_checkbox
     If String($oImg_Checkbox.className) = "imgChkBox" Then
       $Checkbox_count = $Checkbox_count+1
       $checkbox_array[$Checkbox_count] = $oImg_Checkbox.id
       ;WriteToFile($outputFile,"Debug"&$checkbox_array[$Checkbox_count])
        EndIf
    Next

if ($Checkbox_count = -1) Then
        if Not ControlCommand("", "", $SIMPLE_Clearchks_btnID,"IsEnabled") Then
            WriteToFile($outputFile, "ClearChecks button is not enabled as expected")
        Else
            WriteToFile($outputFile, "ClearChecks button is enabled and should not be")
            $flagFail = 1
        EndIf
    Else
        if ControlCommand("", "", $SIMPLE_Clearchks_btnID,"IsEnabled") Then
            WriteToFile($outputFile, "ClearChecks button is enabled as expected")
        Else
            WriteToFile($outputFile, "Fail: ClearChecks button is not enabled and should be")
            $flagFail = 1
        EndIf
    EndIf

FlagFail($ClearChecksStr)
EndFunc

 

;These are autoit libraries point to the AutoIT Directory.
#include <ie.au3>
#include <Array.au3>
#include <String.au3>
#include "wd_helper.au3"
#include "wd_capabilities.au3"

;This is relative path to the script
#include "NxViewFunctions.au3"

;AutoItSetOption is required for the click and drag done to open they System Admin Window.
AutoItSetOption("MouseClickDragDelay",6000)
$testResultFile = "SIMPLETestResults_English_NxView.txt"
$SummaryFile = "SIMPLETestResultsSummary_English_NxView.txt"
Global $HelpFilePath = "file:///C:/Program%20Files/NxStage/NxView/en-US/"

;Pass in the output strings to the function file.
OutputReport($testResultFile, $SummaryFile)
;------------------------------------------------------------------------------------------------------------------------
; Delete output file if it initially exists
If FileExists("SIMPLETestResults_English_NxView.txt") Then
    FileClose("SIMPLETestResults_English_NxView.txt")
    FileDelete("SIMPLETestResults_English_NxView.txt")
EndIf

If FileExists("SIMPLETestResultsSummary_English_NxView.txt") Then
    FileClose("SIMPLETestResultsSummary_English_NxView.txt")
    FileDelete("SIMPLETestResultsSummary_English_NxView.txt")
EndIf
;------------------------------------------------------------------------------------------
WriteToFile($testResultFile,"Script Start Time is: ")
RegistryEdit(0)

;Get the file version from Nx.NxView.exe.
$fileVersion = FileGetVersion("C:\Program Files\NxStage\NxView\Nx.NxView.exe")
FileWriteLine($SummaryFile , "The Software Version being tested is: " & $fileVersion & @CRLF & @CRLF)
FileWriteLine($testResultFile, "The Software Version being tested is: " & $fileVersion & @CRLF & @CRLF)
sleep(8000)

;Set the language and open NxView.
SetLanguage("en-US")

;------------------------------------------------------------------------------------------
;Open the SIMPLE window.
Screenshot(1, "TherapyPage")
;ButtonClick("", "",$AppBarBtnID)
sleep(8000)
WinActivate("","Effluent")
ButtonClick("", "", $SIMPLEBtnID)
sleep(8000)
;Click on the Clear Checks button to start off fresh
ButtonClick("frmHelp", "", $SIMPLE_Clearchks_btnID)
FileWriteLine($testResultFile,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)
FileWriteLine($SummaryFile ,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)
;-----------------------------------------------------------------------------------------------------------------------------------
;Testing the SIMPLE button links.
;The test case numbers correspond to the manual testing test number in the test procedure.
WriteToFile($testResultFile,"Test Case TP0186:10 Start Time is: ")
WriteToFile($SummaryFile,"Test Case TP0186:10 Start Time is: ")
WriteToFile($testResultFile,"This Test case verifies the SIMPLE screen has buttons for each letter of SIMPLE and those button links work for each SIMPLE window.")
WriteToFile($SummaryFile,"This Test case verifies the SIMPLE screen has buttons for each letter of SIMPLE and those button links work for each SIMPLE window.")
WriteToFile($SummaryFile,"This Test case will also verify the correct page appears with cartridge type 0")
;WriteToFile($testResultFile,"The Following requirements are verified: 150, 665, 666")

    WinWait("frmHelp", "", 10)
    SIMPLE_BUTTONS_Setup($HelpFilePath)
    Sleep (10000)
    ButtonClick("","",$AppBarBtnID)
    sleep(8000)
    ButtonClick("","", $SIMPLEBtnID)
    WinWait("frmHelp","",10)


    SIMPLE_BUTTONS_Initiate($HelpFilePath)
    Sleep (10000)
    ButtonClick("", "",$AppBarBtnID)
    sleep(8000)
    ButtonClick("", "", $SIMPLEBtnID)
    WinWait("frmHelp","",10)

    SIMPLE_BUTTONS_Make($HelpFilePath)
    Sleep (10000)
    ButtonClick("", "",$AppBarBtnID)
    sleep(8000)
    ButtonClick("", "", $SIMPLEBtnID)
    WinWait("frmHelp","",10)

    SIMPLE_BUTTONS_Program($HelpFilePath)
    Sleep (10000)
    ButtonClick("", "",$AppBarBtnID)
    sleep(8000)
    ButtonClick("", "", $SIMPLEBtnID)
    WinWait("frmHelp","",10)

    SIMPLE_BUTTONS_Launch($HelpFilePath)
    sleep(8000)

    CloseNxView()
WriteToFile($testResultFile,"Test Case TP0186:10 End Time is: ")
WriteToFile($SummaryFile,"Test Case TP0186:10 End Time is: ")
FileWriteLine($testResultFile,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)
FileWriteLine($SummaryFile ,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)

;------------------------------------------------------------------------------------------------------------------------

 

 

image.thumb.png.296dc6876cfd1230e21cf2b462412dd8.png


Original IE code script+function.

#include <ie.au3>
#include <Array.au3>
#include <String.au3>

;This is relative path to the script
#include "NxViewFunctions.au3"

;AutoItSetOption is required for the click and drag done to open they System Admin Window.
AutoItSetOption("MouseClickDragDelay",6000)
$testResultFile = "SIMPLETestResults_English_NxView.txt"
$SummaryFile = "SIMPLETestResultsSummary_English_NxView.txt"
Global $HelpFilePath = "file:///C:/Program%20Files/NxStage/NxView/en-US/"

;Pass in the output strings to the function file.
OutputReport($testResultFile, $SummaryFile)
;------------------------------------------------------------------------------------------------------------------------
; Delete output file if it initially exists
If FileExists("SIMPLETestResults_English_NxView.txt") Then
    FileClose("SIMPLETestResults_English_NxView.txt")
    FileDelete("SIMPLETestResults_English_NxView.txt")
EndIf

If FileExists("SIMPLETestResultsSummary_English_NxView.txt") Then
    FileClose("SIMPLETestResultsSummary_English_NxView.txt")
    FileDelete("SIMPLETestResultsSummary_English_NxView.txt")
EndIf
;------------------------------------------------------------------------------------------
WriteToFile($testResultFile,"Script Start Time is: ")
RegistryEdit(0)

;Get the file version from Nx.NxView.exe.
$fileVersion = FileGetVersion("C:\Program Files\NxStage\NxView\Nx.NxView.exe")
FileWriteLine($SummaryFile , "The Software Version being tested is: " & $fileVersion & @CRLF & @CRLF)
FileWriteLine($testResultFile, "The Software Version being tested is: " & $fileVersion & @CRLF & @CRLF)
sleep(8000)

;Set the language and open NxView.
SetLanguage("en-US")

;------------------------------------------------------------------------------------------
;Open the SIMPLE window.
Screenshot(1, "TherapyPage")
;ButtonClick("", "",$AppBarBtnID)
sleep(8000)
WinActivate("","Effluent")
ButtonClick("", "", $SIMPLEBtnID)
sleep(8000)
;Click on the Clear Checks button to start off fresh
ButtonClick("frmHelp", "", $SIMPLE_Clearchks_btnID)
FileWriteLine($testResultFile,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)
FileWriteLine($SummaryFile ,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)
;-----------------------------------------------------------------------------------------------------------------------------------
;Testing the SIMPLE button links.
;The test case numbers correspond to the manual testing test number in the test procedure.
WriteToFile($testResultFile,"Test Case TP0186:10 Start Time is: ")
WriteToFile($SummaryFile,"Test Case TP0186:10 Start Time is: ")
WriteToFile($testResultFile,"This Test case verifies the SIMPLE screen has buttons for each letter of SIMPLE and those button links work for each SIMPLE window.")
WriteToFile($SummaryFile,"This Test case verifies the SIMPLE screen has buttons for each letter of SIMPLE and those button links work for each SIMPLE window.")
WriteToFile($SummaryFile,"This Test case will also verify the correct page appears with cartridge type 0")
;WriteToFile($testResultFile,"The Following requirements are verified: 150, 665, 666")

    WinWait("frmHelp", "", 10)
    SIMPLE_BUTTONS_Setup($HelpFilePath)
    Sleep (10000)
    ButtonClick("","",$AppBarBtnID)
    sleep(8000)
    ButtonClick("","", $SIMPLEBtnID)
    WinWait("frmHelp","",10)


    SIMPLE_BUTTONS_Initiate($HelpFilePath)
    Sleep (10000)
    ButtonClick("", "",$AppBarBtnID)
    sleep(8000)
    ButtonClick("", "", $SIMPLEBtnID)
    WinWait("frmHelp","",10)

    SIMPLE_BUTTONS_Make($HelpFilePath)
    Sleep (10000)
    ButtonClick("", "",$AppBarBtnID)
    sleep(8000)
    ButtonClick("", "", $SIMPLEBtnID)
    WinWait("frmHelp","",10)

    SIMPLE_BUTTONS_Program($HelpFilePath)
    Sleep (10000)
    ButtonClick("", "",$AppBarBtnID)
    sleep(8000)
    ButtonClick("", "", $SIMPLEBtnID)
    WinWait("frmHelp","",10)

    SIMPLE_BUTTONS_Launch($HelpFilePath)
    sleep(8000)

    CloseNxView()
WriteToFile($testResultFile,"Test Case TP0186:10 End Time is: ")
WriteToFile($SummaryFile,"Test Case TP0186:10 End Time is: ")
FileWriteLine($testResultFile,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)
FileWriteLine($SummaryFile ,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)

#include <ie.au3>
#include <Array.au3>
#include <String.au3>

;This is relative path to the script
#include "NxViewFunctions.au3"

;AutoItSetOption is required for the click and drag done to open they System Admin Window.
AutoItSetOption("MouseClickDragDelay",6000)
$testResultFile = "SIMPLETestResults_English_NxView.txt"
$SummaryFile = "SIMPLETestResultsSummary_English_NxView.txt"
Global $HelpFilePath = "file:///C:/Program%20Files/NxStage/NxView/en-US/"

;Pass in the output strings to the function file.
OutputReport($testResultFile, $SummaryFile)
;------------------------------------------------------------------------------------------------------------------------
; Delete output file if it initially exists
If FileExists("SIMPLETestResults_English_NxView.txt") Then
    FileClose("SIMPLETestResults_English_NxView.txt")
    FileDelete("SIMPLETestResults_English_NxView.txt")
EndIf

If FileExists("SIMPLETestResultsSummary_English_NxView.txt") Then
    FileClose("SIMPLETestResultsSummary_English_NxView.txt")
    FileDelete("SIMPLETestResultsSummary_English_NxView.txt")
EndIf
;------------------------------------------------------------------------------------------
WriteToFile($testResultFile,"Script Start Time is: ")
RegistryEdit(0)

;Get the file version from Nx.NxView.exe.
$fileVersion = FileGetVersion("C:\Program Files\NxStage\NxView\Nx.NxView.exe")
FileWriteLine($SummaryFile , "The Software Version being tested is: " & $fileVersion & @CRLF & @CRLF)
FileWriteLine($testResultFile, "The Software Version being tested is: " & $fileVersion & @CRLF & @CRLF)
sleep(8000)

;Set the language and open NxView.
SetLanguage("en-US")

;------------------------------------------------------------------------------------------
;Open the SIMPLE window.
Screenshot(1, "TherapyPage")
;ButtonClick("", "",$AppBarBtnID)
sleep(8000)
WinActivate("","Effluent")
ButtonClick("", "", $SIMPLEBtnID)
sleep(8000)
;Click on the Clear Checks button to start off fresh
ButtonClick("frmHelp", "", $SIMPLE_Clearchks_btnID)
FileWriteLine($testResultFile,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)
FileWriteLine($SummaryFile ,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)
;-----------------------------------------------------------------------------------------------------------------------------------
;Testing the SIMPLE button links.
;The test case numbers correspond to the manual testing test number in the test procedure.
WriteToFile($testResultFile,"Test Case TP0186:10 Start Time is: ")
WriteToFile($SummaryFile,"Test Case TP0186:10 Start Time is: ")
WriteToFile($testResultFile,"This Test case verifies the SIMPLE screen has buttons for each letter of SIMPLE and those button links work for each SIMPLE window.")
WriteToFile($SummaryFile,"This Test case verifies the SIMPLE screen has buttons for each letter of SIMPLE and those button links work for each SIMPLE window.")
WriteToFile($SummaryFile,"This Test case will also verify the correct page appears with cartridge type 0")
;WriteToFile($testResultFile,"The Following requirements are verified: 150, 665, 666")

    WinWait("frmHelp", "", 10)
    SIMPLE_BUTTONS_Setup($HelpFilePath)
    Sleep (10000)
    ButtonClick("","",$AppBarBtnID)
    sleep(8000)
    ButtonClick("","", $SIMPLEBtnID)
    WinWait("frmHelp","",10)


    SIMPLE_BUTTONS_Initiate($HelpFilePath)
    Sleep (10000)
    ButtonClick("", "",$AppBarBtnID)
    sleep(8000)
    ButtonClick("", "", $SIMPLEBtnID)
    WinWait("frmHelp","",10)

    SIMPLE_BUTTONS_Make($HelpFilePath)
    Sleep (10000)
    ButtonClick("", "",$AppBarBtnID)
    sleep(8000)
    ButtonClick("", "", $SIMPLEBtnID)
    WinWait("frmHelp","",10)

    SIMPLE_BUTTONS_Program($HelpFilePath)
    Sleep (10000)
    ButtonClick("", "",$AppBarBtnID)
    sleep(8000)
    ButtonClick("", "", $SIMPLEBtnID)
    WinWait("frmHelp","",10)

    SIMPLE_BUTTONS_Launch($HelpFilePath)
    sleep(8000)

    CloseNxView()
WriteToFile($testResultFile,"Test Case TP0186:10 End Time is: ")
WriteToFile($SummaryFile,"Test Case TP0186:10 End Time is: ")
FileWriteLine($testResultFile,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)
FileWriteLine($SummaryFile ,"------------------------------------------------------------------------------------------------------------------------" & @CRLF & @CRLF)

 

 

Posted (edited)

Decided to write something with a little more detail and screenshot to make sense.

 

Your response:

  Quote

 

There are a few issues here --

You're missing the $sStrategy parameter
It is only going to return a single element. You need to pass True for the $bMultiple parameter in order to return an array of matching elements
You should adjust your selector to only return images with the matching class

 

Expand  

 

$oImgs_checkbox = _WD_FindElement($oIE, , , True, "imgChkBox")

$sStrategy    - Locator strategy. See defined constant $_WD_LOCATOR_* for allowed values

 

The examples I saw that used $sStrategy/$_WD_LOCATOR_ were finding paths.

 

I have lets say 9 checkboxes on this page. And to create the array of them. It sounds like I need to use $bMultiple parameter because there are numerous. I want to identify them by the name which from the page source looks to be imgChkBox.

To use Find elements, do I need to provide the WD_Locator parameter and then also provide the object.

 

I also asked a new question in there. Prior with IE, we had just found the name of the item which was "img" and it created the array of all the checkboxes.

Sounds like this is a bit different.

 

From examples i've seen that people are using webdriver for are web base automation. I figured I'd share a screenshot to help express what it is.

We have a windows embedded application that is grabbing this HTML pages. Inside the HTML it has dropdown menu's and checkboxes. 

Edited by Mugaro
Posted
  On 5/30/2024 at 4:54 PM, Mugaro said:

The examples I saw that used $sStrategy/$_WD_LOCATOR_ were finding paths.

Expand  

Yes, because that is how you have to do it in this new era of Webdriver.

  Quote

 To use Find elements, do I need to provide the WD_Locator parameter and then also provide the object.

Expand  

You need to use one of the available locators and also a matching selector.

  Quote

We have a windows embedded application that is grabbing this HTML pages

Expand  

This may be your biggest challenge. Have you even determined if you can connect via Webdriver to the embedded HTML pages?

Posted
  On 5/30/2024 at 8:54 PM, Danp2 said:

Yes, because that is how you have to do it in this new era of Webdriver.

You need to use one of the available locators and also a matching selector.

This may be your biggest challenge. Have you even determined if you can connect via Webdriver to the embedded HTML pages?

Expand  

Okay i'll try to see what the locator would be. 

 

I have a function 

Func BrowserControlFocus()
; Set focus on the Browser control - write which page is being tested and the location of the file.
; Output the name and location of the html page being tested.
sleep(5000)
$hWnd=WinGetHandle("[CLASS:Chrome_RenderWidgetHostHWND; INSTANCE:1]")
$oIE = _WD_Attach($hWnd,"embedded")
_WD_LoadWait($oIE)
WriteToFile($outputFile,"The displayed page is the: " &_WD_Action($oIE, "title") & " page")
WriteToFile($outputFile,"File Location is: " & _WD_Action($oIE, "locationurl"))
EndFunc

We modified this and it seems to be working. If it wasn't it wouldn't move to grab the screen I think, I could be wrong.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...