Jump to content

WebDriver UDF - Help & Support


Recommended Posts

I am connecting to a website that has "windows authentication" enabled. Basic and digest is not enabled.

_WD_Startup()
_WD_Navigate($sSession, "http://gdcvmav02.rwgroup.org")
ConsoleWrite('Page Source => ' & _WD_GetSource($sSession) & @CRLF)

As long as the windows user is a domain user the above code works fine.

When I run the code with a local user, I am prompted with a login window. The _WD_Navigate call only returns after i press cancel, so entering values in the username box is not possible.So I tried adding username and password to $sDesiredCapabilities. But that does not work either.

_WD_Startup()
Local $Data1 = Json_Decode($sDesiredCapabilities)
Json_Put($Data1, ".user", "MyUserName")
Json_Put($Data1, ".password", "MyPassword")
Json_Put($Data1, ".capabilities.alwaysMatch.user", "MyUserName")
Json_Put($Data1, ".capabilities.alwaysMatch.password", "MyPassword")
$sDesiredCapabilities = Json_Encode($Data1)

_WD_Navigate($sSession, "http://gdcvmav02.rwgroup.org")
ConsoleWrite('Page Source => ' & _WD_GetSource($sSession) & @CRLF)

Any suggestions how to authenticate?

2018-07-26 11_26_42-GDCVMAS107, PSM Address - psm.rwgroup.org - Remote Desktop Connection.png

Link to comment
Share on other sites

Hello @begunrom I think you can pass your credential in the url like:

http://username:password@gdcvmav02.rwgroup.org

Saludos

Link to comment
Share on other sites

4 minutes ago, Danp2 said:

This is because Chromedriver doesn't currently support this functionality. Details can be found here.

P.S. You can see their overall implementation status here.

Thank you @Danp2.  I'm looking to implement many of the actions listed here. On the status list they are showing '/session/{session id}/actions' as incomplete. Only for some actions or for all actions? let me know if you have an idea regarding this :)

 

 

Link to comment
Share on other sites

13 minutes ago, Danp2 said:

The fact that it returns the error "unknown command" indicates to me that Chromedriver doesn't currently support any use of the Actions API. ;)

Try switching to Firefox if you need this functionality right away.

Yes, Thank you :)

Link to comment
Share on other sites

Succeeded in setting data on a drop down list. Hope it will help someone.

Reference

 Set value on a drop down list By Index, value or text.

Local $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElementId & '"}'
Local $sResponse = _WD_ExecuteScript($sSession, "var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ if(select.options[i].index == 1){ select.options[i].selected = true; } }", $sJsonElement ) ;Index
Local $sResponse = _WD_ExecuteScript($sSession, "var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ if(select.options[i].value == '1'){ select.options[i].selected = true; } }", $sJsonElement );value
Local $sResponse = _WD_ExecuteScript($sSession, "var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ if(select.options[i].text == '1'){ select.options[i].selected = true; } }", $sJsonElement );text

 

Link to comment
Share on other sites

@Danp2, Thank you so much for testing the piece of code and finding that out. We have got a fix for that. Please refer the sixth answer here. 

; #FUNCTION# ===========================================================================================================
; Name ..........: _WD_SetDropDownOption
; Description ...: Select a Drop down option by value, index or text
; Syntax ........: _WD_SetDropDownOption($sSession, $sElement, $svalue[, $iMethod = 1,])
; Parameters ....: $sSession            - Session ID from _WDCreateSession
;                  $sElement            - Element ID from _WDFindElement
;                  $iMethod             - [optional] an integer value. Default is 1.
;                  1=Select option by value
;                  2=Select option by index
;                  3=Select option by text
; Return values .: Nil
; Author ........:
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_SetDropDownOption($sSession, $sElement, $sValue, $iMethod = 1)
    Local $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}'
    Local $Query = ""
    Switch $iMethod
        Case 1
            $Query = "var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ if(select.options[i].value == " & "'" &  $sValue & "'" & "){ select.options[i].selected = true; arguments[0].onchange();return } }"
        Case 2
            $Query = "var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ if(select.options[i].index == " & $sValue & "){ select.options[i].selected = true; arguments[0].onchange();return } }"
        Case 3
            $Query = "var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ if(select.options[i].text == " & "'" &  $sValue & "'" & "){ select.options[i].selected = true; arguments[0].onchange();return } }"
    EndSwitch
    If $Query <> "" Then Local $sResponse = _WD_ExecuteScript($sSession, $Query , $sJsonElement )
    Return
EndFunc   ;==>_WD_SetDropDownOption

 

Edited by PoojaKrishna
Added a method to set option on Dropdown
Link to comment
Share on other sites

@PoojaKrishna Please try this as a solution that uses the existing UDF functions to locate and then click the desired option --

Func _WD_ElementOptionSelect($sSession, $sStrategy, $sSelector, $sStartElement = "")
    Local $sElement = _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement)

    If @error = $_WD_ERROR_Success Then
        _WD_ElementAction($sSession, $sElement, 'click')
    EndIf
EndFunc

In my limited testing, this works and triggers the underlying events. Let me know if you encounter a problem or find where this solution doesn't cover some options that your's does.

Dan

Link to comment
Share on other sites

1 hour ago, Danp2 said:

@PoojaKrishna Please try this as a solution that uses the existing UDF functions to locate and then click the desired option --

Func _WD_ElementOptionSelect($sSession, $sStrategy, $sSelector, $sStartElement = "")
    Local $sElement = _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement)

    If @error = $_WD_ERROR_Success Then
        _WD_ElementAction($sSession, $sElement, 'click')
    EndIf
EndFunc

In my limited testing, this works and triggers the underlying events. Let me know if you encounter a problem or find where this solution doesn't cover some options that your's does.

Dan

Yes, it works. I was looking for a method to set by index, value and text :-)

 

Edited by PoojaKrishna
Link to comment
Share on other sites

Hi guys,

I am trying to automate a website, but it requires a certificate. When using the following code:

#include "wd_core.au3"
#include "wd_helper.au3"
Local $sDesiredCapabilities

SetupChrome()

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://my website")

Func SetupChrome()
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}'
EndFunc

I am having difficulties, because of _WD_Navigate. It waits for the website to load, but Chrome requires certificate selection. Without me selecting the certificate manually, the code does not continue. Is there a way that I can ask _WD_Navigate to not wait for the page load?

Link to comment
Share on other sites

Just figured out how to scroll an element into view and thought I would stick it here.

not surprisingly, it appears that Chrome uses a different command than firefox and IE.  I've only tested the Chrome version.

            Local $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $eReturnedFromFind & '"}'
            $sResponse = _WD_ExecuteScript($sSession, "return arguments[0].scrollIntoViewIfNeeded(true)", $sJsonElement)
 

 

Firefox:  not tested but should be 

            Local $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $eReturnedFromFind & '"}'
            $sResponse = _WD_ExecuteScript($sSession, "return arguments[0].scrollIntoView(true)", $sJsonElement)

 

 

Link to comment
Share on other sites

On 7/30/2018 at 9:43 PM, Danp2 said:

Right... I would think this would be possible with the existing options (CSS Selector or XPath) in _WD_FindElement. Can you test to see if this is possible?

Yes, will test and update here.

Got a way to get the Xpath of an element using a java script. Working good with Chrome in my testings.

$Query = "var paths = [];" & @CRLF & _
    "for ( ; arguments[0] && arguments[0].nodeType == Node.ELEMENT_NODE; arguments[0] = arguments[0].parentNode )  {" & @CRLF & _
        "var index = 0;"& @CRLF & _
        "for ( var sibling = arguments[0].previousSibling; sibling; sibling = sibling.previousSibling ) {"& @CRLF & _
            "if ( sibling.nodeType == Node.DOCUMENT_TYPE_NODE ) {"& @CRLF & _
                "continue;"& @CRLF & _
            "}"& @CRLF & _
            "if ( sibling.nodeName == arguments[0].nodeName ) {"& @CRLF & _
                "++index;"& @CRLF & _
            "}"& @CRLF & _
        "}"& @CRLF & _
        "var tagName = arguments[0].nodeName.toLowerCase();"& @CRLF & _
        "var pathIndex = '[' + (index+1) + ']';"& @CRLF & _
        "paths.unshift( tagName + pathIndex );"& @CRLF & _
    "}"& @CRLF & _
    "return paths.length ? '/' + paths.join( '/') : null;"
    Local $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElementId & '"}'
    Local $sResponse = _WD_ExecuteScript($sSession, $Query , $sJsonElement )
    $oJson = Json_Decode($sResponse)
    $sResult = Json_Get($oJson, "[value]")

Reference here.

Link to comment
Share on other sites

I'm trying to clean up the console output while running.  My console is getting crazy huge especially since I have a lot of Wait until's in my script.

 

I have already set the $_WD_DEBUG = False but i'm still getting a lot of console output.

it looks like the __WD_Error is what is sending all of the outputs to console even on Success no matter what.

 

I added a line to the top of the __WD_Error() function:  If $_WD_DEBUG = False Then Return $i_WD_ERROR

That seemed to do the trick, but as that function is used by just about everything else, I'm not sure if it was a great fix or not.

 

 

Link to comment
Share on other sites

35 minutes ago, BigDaddyO said:

$_WD_DEBUG

Perhaps it would be a good idea to expand this from True/False to a set of of enums, such as --

Global Enum _
        $_WD_DEBUG_None = 0, _ ; No logging to console
        $_WD_DEBUG_Error,    _ ; Error logging to console
        $_WD_DEBUG_Info        ; Full logging to console

 

Link to comment
Share on other sites

I added that Global Enum to my wd_core.au3

Looks like all the changes only need to be made in the wd_core.au3 as the wd_helper doesn't seem to reference the $_WD_DEBUG at all.

I made the change to each of the functions, but after finishing. it looks like it would have been accomplished by doing a simple find replace:

If $_WD_DEBUG Then

replace with

If $_WD_DEBUG = $_WD_DEBUG_Info Then
 

 

for the __WD_Error() I added these as the first two lines

    If $_WD_DEBUG = $_WD_DEBUG_None Then Return $i_WD_ERROR      ; No logging to console
    If $_WD_DEBUG = $_WD_DEBUG_Error and $i_WD_ERROR = $_WD_ERROR_Success Then Return $i_WD_ERROR
 

 

 

I tested with my Chrome script using each of the debug types and they all seem to do what they should.

 

The individual functions I manually updated

_WD_Startup()
_WD_CreateSession()
_WD_DeleteSession()
_WD_Status()
_WD_Timeouts()
_WD_Navigate()
_WD_Action()
_WD_Window()
_WD_FindElement()
_WD_ElementAction()
_WD_ExecuteScript()
_WD_Alert()
_WD_GetSource()
_WD_Cookies()
__WD_Get()
__WD_Get()
__WD_Post()    <= This one had 2 change in it
__WD_Delete()    <= This one had 2 change in it

 

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...