Jump to content

Recommended Posts

Posted

Hello

So I'm trying to fix some of our functions that were IE based with the WebDriver.

Func CheckBoxID()
_WD_LoadWait($oIE)
Global $Checkbox_count = -1
$oImgs_checkbox = _WD_FindElement($oIE, "img")
$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

The issue: $oImgs_checkbox = _WD_FindElement($oIE, "img")

 

We have checkboxes on the page that gets called in our windows embedded application. It will register how many checkboxes their are. The old IE function would just need: ($oIE, "img")

 

This is the WD Find Element function:

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_FindElement
; Description ...: Find element(s) by designated strategy.
; Syntax ........: _WD_FindElement($sSession, $sStrategy, $sSelector[, $sStartNodeID = Default[, $bMultiple = Default[,
;                  $bShadowRoot = Default]]])
; Parameters ....: $sSession     - Session ID from _WD_CreateSession
;                  $sStrategy    - Locator strategy. See defined constant $_WD_LOCATOR_* for allowed values
;                  $sSelector    - Indicates how the WebDriver should traverse through the HTML DOM to locate the desired element(s).
;                  $sStartNodeID - [optional] Element ID to use as starting HTML node. Default is ""
;                  $bMultiple    - [optional] Return multiple matching elements? Default is False
;                  $bShadowRoot  - [optional] Starting HTML node is a shadow root? Default is False
; Return values .: Success - Element ID(s) returned by web driver.
;                  Failure - "" (empty string) and sets @error to one of the following values:
;                  - $_WD_ERROR_Exception
;                  - $_WD_ERROR_NoMatch
;                  - $_WD_ERROR_InvalidExpression
; Author ........: Danp2
; Modified ......:
; Remarks .......: An array of matching elements is returned when $bMultiple is True.
; Related .......: _WD_LastHTTPResult
; Link ..........: https://www.w3.org/TR/webdriver#element-retrieval
; Example .......: No
; ===============================================================================================================================

 

How do I determine what syntax is needed to properly store the checkboxes and not break my script?

Posted
4 hours ago, Mugaro said:
$oImgs_checkbox = _WD_FindElement($oIE, "img")

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

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...