Skip to content

Misc fixes #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions wd_core.au3
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
; AutoIt Version : v3.3.14.2
; ==============================================================================
#cs
V0.1.0.5
- Fixed: Missing variable declarations
- Changed:

V0.1.0.5
- Changed: Switched to using _WinHttp functions
- Added: _WD_LinkClickByText
Expand Down Expand Up @@ -82,7 +86,7 @@


#Region Global Constants
Global Const $__WDVERSION = "0.1.0.5"
Global Const $__WDVERSION = "0.1.0.6"

Global Const $_WD_LOCATOR_ByID = "id"
Global Const $_WD_LOCATOR_ByName = "name"
Expand All @@ -107,9 +111,9 @@ Global Enum _
$_WD_ERROR_RetValue, _ ; Error echo from Repl e.g. _WDAction("fullscreen","true") <> "true"
$_WD_ERROR_Exception, _ ; Exception from web driver
$_WD_ERROR_InvalidExpression, _ ; Invalid expression in XPath query or RegEx
$_WD_ERROR_COUTNER ;
$_WD_ERROR_COUNTER ;

Global Const $aWD_ERROR_DESC[$_WD_ERROR_COUTNER] = [ _
Global Const $aWD_ERROR_DESC[$_WD_ERROR_COUNTER] = [ _
"Success", _
"General Error", _
"Socket Error", _
Expand Down Expand Up @@ -424,7 +428,7 @@ EndFunc
; ===============================================================================================================================
Func _WD_Window($sSession, $sCommand, $sOption = '')
Local Const $sFuncName = "_WD_Window"
Local $sResponse, $sJSON, $sResult = ""
Local $sResponse, $sJSON, $sResult = "", $iErr

$sCommand = StringLower($sCommand)

Expand Down Expand Up @@ -599,7 +603,7 @@ EndFunc ;==>_WDFindElement
; ===============================================================================================================================
Func _WD_ElementAction($sSession, $sElement, $sCommand, $sOption='')
Local Const $sFuncName = "_WD_ElementAction"
Local $sResponse, $sResult = '', $iErr
Local $sResponse, $sResult = '', $iErr, $oJson

$sCommand = StringLower($sCommand)

Expand Down
70 changes: 39 additions & 31 deletions wd_helper.au3
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ EndFunc
; | HTML
; Return values .: Success - String representing handle of matching tab
; Failure - blank string
; @ERROR - $_WD_ERROR_Success
; - $_WD_ERROR_InvalidDataType
; - $_WD_ERROR_NoMatch
; - $_WD_ERROR_GeneralError
; Author ........: Dan Pollak
; Modified ......:
; Remarks .......:
Expand All @@ -98,37 +102,41 @@ Func _WD_Attach($sSession, $sString, $sMode = 'title')
Local $sCurrentTab = _WD_Window($sSession, 'window')
Local $aHandles = _WD_Window($sSession, 'handles')

$sMode = StringLower($sMode)

For $sHandle In $aHandles

_WD_Window($sSession, 'Switch', '{"handle":"' & $sHandle & '"}')

Switch $sMode
Case "title", "url"
If StringInStr(_WD_Action($sSession, $sMode), $sString) > 0 Then
$lFound = True
$sTabHandle = $sHandle
ExitLoop
EndIf

Case 'html'
If StringInStr(_WD_GetSource($sSession), $sString) > 0 Then
$lFound = True
$sTabHandle = $sHandle
ExitLoop
EndIf

Case Else
SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, "(Title|URL|HTML) $sOption=>" & $sMode))
Return ""
EndSwitch
Next

If Not $lFound Then
; Restore prior active tab
_WD_Window($sSession, 'Switch', '{"handle":"' & $sCurrentTab & '"}')
SetError(__WD_Error($sFuncName, $_WD_ERROR_NoMatch))
If @error = $_WD_ERROR_Success Then
$sMode = StringLower($sMode)

For $sHandle In $aHandles

_WD_Window($sSession, 'Switch', '{"handle":"' & $sHandle & '"}')

Switch $sMode
Case "title", "url"
If StringInStr(_WD_Action($sSession, $sMode), $sString) > 0 Then
$lFound = True
$sTabHandle = $sHandle
ExitLoop
EndIf

Case 'html'
If StringInStr(_WD_GetSource($sSession), $sString) > 0 Then
$lFound = True
$sTabHandle = $sHandle
ExitLoop
EndIf

Case Else
SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, "(Title|URL|HTML) $sOption=>" & $sMode))
Return ""
EndSwitch
Next

If Not $lFound Then
; Restore prior active tab
_WD_Window($sSession, 'Switch', '{"handle":"' & $sCurrentTab & '"}')
SetError(__WD_Error($sFuncName, $_WD_ERROR_NoMatch))
EndIf
Else
SetError(__WD_Error($sFuncName, $_WD_ERROR_GeneralError))
EndIf

Return $sTabHandle
Expand Down
2 changes: 1 addition & 1 deletion wd_test.au3
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ EndFunc

;_WDWindow($sSession, 'frame', '{"id":nullelse
Func TestElements()
Local $sElement
Local $sElement, $aElements, $sValue

_WD_Navigate($sSession, "http://google.com")
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib1']")
Expand Down