Jump to content

WebDriver UDF - Help & Support

Recommended Posts

Alright, so I've been working with geckodriver and Firefox now, and I need to submit a bug to them about a very specific case that I'm dealing with. In order to get the trace log to them, I need to push geckodriver's output to a .log file, but for some reason AutoIt keeps screwing it up.

The code I run is as follows:

_WD_Option("Driver", "C:\Path\To\geckodriver.exe")
_WD_Option("Port", 4444)
_WD_Option("DriverParams", '-vv >C:\Path\To\geckodriver.log')
Local $oId = _WD_Startup()

Which then gives me the error:

error: Found argument '>geckodriver.log' which wasn't expected, or isn't valid in this context

    geckodriver.exe -v

For more information try --help

This is a problem because if I run the command that's being generated in a cmd window myself, then it runs the geckodriver.exe fine and outputs to the log file as I specified. This might not actually be a problem with your UDF, but with AutoIt itself because I only get this problem using AutoIt's Run() function.

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.

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

Hello @GregEisenberg You need to do this: Local $oJsonRect=_WD_ElementAction($sSession, $sElements, 'rect') ConsoleWrite("!" & Json_Get($oJsonRect, "[x]") & @CRLF) ConsoleWr

Posted Images

@Redd500 I took a quick look at this, but didn't get the same error as you.  What version of geckodriver are you using?

The issue I encountered is that the redirection to the log file resulted in the command window containing the geckodriver immediately closed. To address your immediate need, you could either copy / paste the log data from the geckodriver console or you could manually launch the webdriver and skip the call to _WD_Startup.


Link to post
Share on other sites

@Danp2 This is because the '>log file' silences geckodriver and outputs it into a log file rather than into the console. I got the error through running the code after compiling it into a .exe using Aut2Exe and its /console flag and then running the .exe through the command prompt. I generally use this for my own testing purposes so I can see where things go wrong using ConsoleWrite() or to view any errors that get written.

Anyways, I managed to get it running using 2 batch files to make it run asynchronously with the log file being created, because I need to run it in Windows Task Scheduler for full automation. Thanks for the suggestion, it got me what I needed. Shame I couldn't use AutoIt though.

Link to post
Share on other sites

I understand about the log file redirection. However, it does compute for me that this would stop the console app from running. I'm guessing that it has something to do with the webdriver running directly in the console that was created by the Run command. The solution is already outlined in the help file --


To run DOS (console) commands, try Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE)    ; don't forget " " before "/c"

I have implemented this change in _WD_Startup and it now works as I would expect.

Link to post
Share on other sites

I thoguht that _WD_Alert($session, 'status') would return True only if any alert message existed. In the following code, the first MsgBox shows 'True' and the second MsgBox shows an empty string (is it really an empty string?) when no MsgBox is expected. Do I misunderstand these functions?

#include "wd_core.au3"

Local $sDesiredCapabilities
$Session = _WD_CreateSession($sDesiredCapabilities)

MsgBox(0,'',_WD_Alert($Session, 'status'))

If _WD_Alert($Session, 'gettext') <> "" Then
    MsgBox(0,'',_WD_Alert($Session, 'gettext'))


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, "args":["start-maximized", "disable-infobars"] }}}}'


Link to post
Share on other sites

@CYCho The initial status check is returning incorrect information when using Chrome because the it returns a different HTTP status code than the UDF is expecting. I will need to research this further to determine how to best comply with the W3C specs.

On the gettext issue, I believe it is returning an object, which would explain why your code is acting this way. Some additional error checking in the UDF will take care of this.


Link to post
Share on other sites
  • 2 weeks later...


i´m not know how to select a text string within a textwindow.

this works

_WD_ExecuteScript($sSession, 'return  document.getElementsByTagName('p')[1].innerHTML;')

__WD_Post: URL=HTTP://; $sData={"script":"return  document.getElementsByTagName('p')[1].innerHTML; ", "args":[[]]}
__WD_Post: StatusCode=200; ResponseText={"value":"test2"}
_WD_ExecuteScript: {"value":"test2"}

But this not

_WD_ExecuteScript($sSession, 'document.getElementsByTagName('p')[1].select;')

__WD_Post: URL=HTTP://; $sData={"script":" document.getElementsByTagName('p')[1].select; ", "args":[[]]}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ExecuteScript: {"value":null}

In the w3school description is a example LINK --> select() with brackets.

If i execute the function without brackets, i got the Status Code 200 back but nothing is selected.

If i excute the function with brackets, i got the status code 500

_WD_ExecuteScript($sSession, 'document.getElementsByTagName('p')[1].select();')

_WD_ExecuteScript: {"value":{"error":"javascript error","message":"TypeError: document.getElementById(...).select is not a function","stacktrace":"execute_script @, line 0\ninline javascript, line 1\nsrc: \"undefined\"\nStack:\n}}

Can someone explain to me what i don´t understand again???

Many thanks


Link to post
Share on other sites

jepp you are right. I changed the script based on that Select <p>

document.getElementsByTagName('p')[1].click(function(){var range ;range = document.createRange();range.selectNodeContents(document.getElementsByTagName('p')[0]);window.getSelection().addRange(range)});
_WD_ExecuteScript($sSession, 'document.getElementsByTagName('p')[1].click(function(){var range ;range = document.createRange();range.selectNodeContents(document.getElementsByTagName('p')[1]);window.getSelection().addRange(range)});')

__WD_Post: URL=HTTP://; $sData={"script":"document.getElementsByTagName('p')[1].click(function(){var range ;range = document.createRange();range.selectNodeContents(document.getElementsByTagName('p')[1]);window.getSelection().addRange(range)});", "args":[[]]}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_ExecuteScript: {"value":null}

But the selection them self is still outstanding.... :-(


Link to post
Share on other sites
7 hours ago, Danp2 said:

A few questions for you --

  1. Can you explain why you need to select this text? What's your end goal here?
  2. Have you tried running your javascript code directly in the browsers console?  This is what I would recommend until you get it working. Then test it using _WD_ExecuteScript.


i´ve got it.

I´m not firm with the syntax, but this workes fine!

1. i dive into the frame

2. i select my paragraph

3. i leave the frame

_WD_Window($sSession, 'frame', '{"id":0}')

_WD_ExecuteScript($sSession, '{var range = document.createRange();range.selectNodeContents(document.getElementById('test'));var sel = window.getSelection();sel.addRange(range);}')

_WD_Window($sSession, 'parent', '{"id":0}')

Best regards,


Edited by horphi
Link to post
Share on other sites
  • 2 weeks later...
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By mLipok
      Recently I start wd_capabilities.au3 project on my side.
      I think this is time to share to AutoIt community.
      Check attached UDF: wd_capabilities.au3

      Here is a scratch example showing how to use them:
      #include "wd_helper.au3" #include "wd_capabilities.au3" _Example() Func _Example() ........ ........ ........ _WD_Capabilities_Build_Arguments(Null) ; CLEANUP ARGS _WD_Capabilities_Build_Arguments('--headless') _WD_Capabilities_Build_Arguments('start-maximized') _WD_Capabilities_Build_Arguments('disable-infobars') _WD_Capabilities_Build_Arguments('user-data-dir', 'C:\Users\' & @UserName & '\AppData\Local\Google\Chrome\User Data\Default') Local $s_WD_Capabilities_Arguments = _WD_Capabilities_Build_Arguments(Default) ; GET ARGS _WD_Capabilities_Build_Preferences(Null) ; CLEANUP PREFS If $s_Download_dir Then _WD_Capabilities_Build_Preferences('download.default_directory', $s_Download_dir) Local $s_WD_Capabilities_Preferences = _WD_Capabilities_Build_Preferences(Default) ; GET PREFS Local $s_Desired_Capabilities = _WD_Capabilities_Build_JSON('chrome', $s_WD_Capabilities_Arguments, $s_WD_Capabilities_Preferences) Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities) ........ ........ ........ EndFunc  
      I plan to publish the code on GitHub.
      In the indefinite future, when the project becomes more functional, if @Danp2 accepts it, I hope it may be included in the main WebDriver UDF.

      I am waiting for yours feedback and help in the further development of this project.

      REMARK 1:
      As so far this UDF only supports GoogleChrome.
      Adding support for other browsers shouldn't be difficult, I just didn't need to.

      REMARK 2:
      For now, this project is working but still as a early BETA, so please do not discuss, ask questions, or post examples or snippets of code that pertain to any function of this UDF in other part of this forum, until it is found acceptable. Simply: discusion and tests only here in this topic.

    • By Danp2
      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.
      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 --
      Please post any questions, suggestions or errors in the GH&S thread.
      Previous support threads (Closed)
    • By Hermes
      I have Index.html where it contains a frame with a source "frame1.html". I can select/highlight elements in index.html but unable to select/highlight elements inside the frame with the src "frame1.html", the autoit output is throwing error:
      __WD_Post: URL=HTTP://; $sData={"using":"css selector","value":"frameset:nth-of-type(1)"} __WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\... __WD_Post ==> No match: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"css selector\",\"selector\":\"frameset:nth-of-type(1)\"}\n (Session info: chrome=90.0.4430.212)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00FCE7D3+124883]\n\tOrdinal0 [0x00FCE7B1+124849]\n\tGetHandleVerifier [0x01218688+193832]\n\tGetHandleVerifier [0x0123C478+340760]\n\tGetHandleVerifier [0x012361F1+315537]\n\tGetHandleVerifier [0x012516BA+427354]\n\tGetHandleVerifier [0x01236176+315414]\n\tGetHandleVerifier [0x0125174A+427498]\n\tGetHandleVerifier [0x0125D6EB+476555]\n\tGetHandleVerifier [0x0125154B+426987]\n\tGetHandleVerifier [0x01234FFD+310941]\n\tGetHandleVerifier [0x01235D8E+314414]\n\tGetHandleVerifier [0x01235D19+314297]\n\tGetHandleVerifier [0x012F31EC+1089676]\n\tGetHandleVerifier [0x012F17C9+1082985]\n\tGetHandleVerifier [0x012F13A3+1081923]\n\tGetHandleVerifier [0x013ED9FD+2115741]\n\tOrdinal0 [0x0111B82E+1488942]\n\tOrdinal0 [0x010B5A7D+1071741]\n\tOrdinal0 [0x010B559B+1070491]\n\tOrdinal0 [0x010B54B1+1070257]\n\tOrdinal0 [0x010EFF53+1310547]\n\tBaseThreadInitThunk [0x770662C4+36]\n\tRtlSubscribeWnfStateChangeNotification [0x776B1B69+1081]\n\tRtlSubscribeWnfStateChangeNotification [0x776B1B34+1028]\n"}} Auto IT Script:
      #Include "wd_core.au3" #Include "wd_helper.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, 'index.html') _WD_LoadWait($sSession) Local $index = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)") Local $index1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)", $index) Local $index2 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frame:nth-of-type(1)", $index1) Local $index3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)", $index2) _WD_HighlightElement($sSession, $index2, 1) _WD_HighlightElement($sSession, $index3, 1) _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":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome  

      frame1.html index.html
    • By Hermes
      Hi, sometimes when I run my script in GUI (SciTe Editor) or as an executable file, the chrome driver launches but the chrome browser does not but when I re-run the script again - chrome driver launches and so does the browser. Here is the error that I'm getting:
      __WD_Post: StatusCode=0; ResponseText=WinHTTP request timed out before Webdriver... __WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver _WD_CreateSession: WinHTTP request timed out before Webdriver _WD_CreateSession ==> Webdriver Exception: HTTP status = 0 Just wondering if there's a way to re-launch both the driver and browser without having to rerun the script/executable.
    • By SkysLastChance
      I am using web driver and xpaths to automate chrome. 
      I am able to edit everything I need to until I get these pop ups. Then when I try to find the xpath it act like it does not exist. 
      This code below is working to find input fields on the main page of the site. But, if I try the same thing for ones in the popover it will not find it. 😕
      $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[substring(@id, string-length(@id) - string-length('_3') + 1 ) = '_3']") _WD_ElementAction($sSession, $sElement, 'value', "TEST") Here is the html

      Any idea why it is not finding the element inside these pop overs?
  • Create New...