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 post
Share on other sites
  • Replies 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

This is the "General Help and Support" thread for the WebDriver UDF. The UDF itself can be downloaded here. So if you have any questions, suggestions or errors please post here.

use the _WD_ElementAction function like this: $sValue = _WD_ElementAction($sSession, $sElement, 'attribute', 'src') p.s. ... and remove @src from the xPath: "//img[@alt='NiceGirl']"

Time ago I wrote a function to extract data from  the source HTML code of tables. https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/ Seems that that fun

Posted Images

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

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

Saludos

Link to post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
Share on other sites
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By levila
      Hi Guys, i just do some codding to automate login to some of the web.
      I manage to do the script but somehow after script done, some weird box popup. and keep looping until i close the main chrome.exe

      here is my code. kinldy pls assist, im very new to webdriver udf.
      #NoTrayIcon #include "wd_core.au3" #include "wd_helper.au3" $_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://someoftheweb.com") _ChromeSetInputValueByName($sSession, "inputName", "Username") _ChromeSetInputValueById($sSession, "inputPassword", "Password") _ChromeSetMouseClick($sSession, "submit", "click") _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--no-sandbox"]}}}}' EndFunc Func _ChromeSetInputValueByName($sSession,$name,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$name&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func _ChromeSetInputValueById($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func _ChromeSetMouseClick($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//button[@type='"&$Id&"']") _WD_ElementAction($sSession, $sButton, 'click', $Value) EndFunc  
    • By RohanM
      Hi Team,
      is there is a way to embed the webpage in auto it GUI using webdriver? what I want to do is that, I want to open edge browser inside the AutoIT GUI, in IE we have _IECreateEmbedded function but for the webdriver I am not able to find a function, please help  
      Rohan M
    • By Danp2
      Introduction
      This UDF will allow you to interact with any browser that supports the W3C WebDriver specifications. Supporting multiple browsers via the same code base is now possible with just a few configuration settings.
      Requirements
      JSON UDF https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn
      WinHTTP UDF https://www.autoitscript.com/forum/topic/84133-winhttp-functions/
      HtmlTable2Array UDF (optional) https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/
      WebDriver for desired browser
      Chrome WebDriver https://sites.google.com/a/chromium.org/chromedriver/downloads FireFox WebDriver https://github.com/mozilla/geckodriver/releases Edge WebDriver https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      See the wiki for details on the UDF --
      https://www.autoitscript.com/wiki/WebDriver
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/205553-webdriver-udf-help-support-iii/
      Previous support threads (Closed)
      https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/
      https://www.autoitscript.com/forum/topic/201106-webdriver-udf-help-support-ii/
       
    • By goku200
      I am trying to change the settings of the print option to Save as PDF and its not changing the settings and clicking on the Save button at the bottom. Here is my script that I have written and the format is correct below. Chrome browser I'm using is 97.0 My script was working fine using Chrome 95.0\ Not sure why its not working now
      It finds the print-preview-app element but not the others.
       
    • By goku200
      I am trying to hit the Return key without having to use the Send keys. I have the following code and its not hitting the Return key. Am I missing something?
      ; Press Return $sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE006"},' ; Pause $sAction &= '{"type": "pause", "duration": 500},' ; Release Return $sAction &= '{"type": "keyUp", "value": "\uE006"}]}]}' _WD_Action($sSession, "actions", $sAction)  
×
×
  • Create New...