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 comment
Share on other sites

@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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

I tested the new UDF in working application and found that:

1. _WD_Alert($session, 'status') produces "False" regardless of the existence of an alert message.

2. _WD_Alert($session, 'gettext') produces an empty string regardless of the existence of an alert message.

3. _WD_Alert($session, 'accept') works properly.

Link to comment
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 comment
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 comment
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 comment
Share on other sites

  • 2 weeks later...
This topic is now closed to further replies.

  • Create New...