Jump to content
Danp2

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

USAGE:
    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.

Share this post


Link to post
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.

 

Share this post


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.

Share this post


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 --

Quote

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.

Share this post


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
SetupChrome()
_WD_Startup()
$Session = _WD_CreateSession($sDesiredCapabilities)

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

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

_WD_Shutdown()


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"] }}}}'
EndFunc

 

Share this post


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.

 

Share this post


Link to post
Share on other sites

Maybe I can use StringLen(_WD_Alert($session, 'gettext')) to check existence of an alert message.

Share this post


Link to post
Share on other sites

The new UDF was fine with the test code above, but in my actual application it seems not right. I will give it a further test and come back with details. Unfortunately I have to go out now and it will be several hours until I can come back.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Hi,

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://127.0.0.1:4444/session/fc4b43b3-2c7b-4ce1-92fb-660e2d017aab/execute/sync; $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://127.0.0.1:4444/session/fc4b43b3-2c7b-4ce1-92fb-660e2d017aab/execute/sync; $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

horphi

Share this post


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://127.0.0.1:4444/session/87406f69-c375-4321-9e48-c0860f247cd2/execute/sync; $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.... :-(

 

Share this post


Link to post
Share on other sites

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.

Share this post


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.

Hi,

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,

horphi

Edited by horphi

Share this post


Link to post
Share on other sites

Hello together,

does somebody know, whether it´s possible to check to progress of loading a webpage and execute script first after 100% load of webpage?

BR

horphi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • 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/
      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/ Function List
      Core Functions
      _WD_CreateSession($sDesiredCapabilities='{}') _WD_DeleteSession($sSession) _WD_Status() _WD_Timeouts($sSession, $sTimeouts = '') _WD_Navigate($sSession, $sURL) _WD_Action($sSession, $sCommand) _WD_Window($sSession, $sCommand, $sOption = '') _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement = "", $lMultiple = False) _WD_ElementAction($sSession, $sElement, $sCommand, $sOption='') _WD_ExecuteScript($sSession, $sScript, $sArguments="[]") _WD_Alert($sSession, $sCommand, $sOption = '') _WD_GetSource($sSession) _WD_Cookies($sSession, $sCommand, $sOption = '') _WD_Option($sOption, $vValue = "") _WD_Startup() _WD_Shutdown() Helper Functions
      _WD_NewTab($sSession, $lSwitch = True, $iTimeout = -1, $sURL = "", $sFeatures = "") _WD_Attach($sSession, $sString, $sMode = 'title') _WD_LinkClickByText($sSession, $sText, $lPartial = True) _WD_WaitElement($sSession, $sElement, $sStrategy, $sSelector[, $iDelay = 0[, $iTimeout = -1]]) _WD_GetMouseElement($sSession) _WD_GetElementFromPoint($sSession, $iX, $iY) _WD_LastHTTPResult() _WD_GetFrameCount() _WD_IsWindowTop() _WD_FrameEnter($sIndexOrID) _WD_FrameLeave() _WD_HighlightElement($sSession, $sElement[, $iMethod = 1]) _WD_HighlightElements($sSession, $aElements[, $iMethod = 1]) _WD_jQuerify($sSession) WD_ElementOptionSelect($sSession, $sStrategy, $sSelector, $sStartElement = "") _WD_ConsoleVisible($lVisible = False) _WD_Screenshot($sSession, $sElement = '', $nOutputType = 1) Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/
    • By Davidowicza
      Hey guys,
      I am creating my very first script that automates a browser (I usually work with program installs and database automation) and have come across an issue that I am totally stumped on. I need to click an element that gives me a drop down list box but the Xpath to the element changes with every instance of chrome I start...
      I have tried selecting the class, rect, and path but no luck. It never finds the element. (I could be doing this wrong since I am not good at HTML)
      Element I need to select:
      This is the Xpath for the last 3 instances of chrome I have run the script with:
      //*[@id="highcharts-5bp9crq-8"]/svg/g[6]/g/rect //*[@id="highcharts-fiw9szv-8"]/svg/g[6]/g/rect //*[@id="highcharts-5szkmx8-8"]/svg/g[6]/g/rect As you can see the path changes every time.
      How I am trying to select the element:
      ;Check for box element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") MsgBox(0, "", "check for timeout") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") _WD_ElementAction($sSession, $sElement, 'click') Maybe someone has come across this before and found a work around without using mouseclick()
      Thanks guys, hopefully I am just very overlooking something simple and can be pointed to the right solution.
      Side Note: I wish I could share the webpage entirety, but it has sensitive information with my agency that I cannot share. If you need more, just let me know and I will try and post as much as I can.
    • By daluu
      This is kind of already posted here:
      '?do=embed' frameborder='0' data-embedContent>>
      but wanted to note this in this forum of example scripts in case some people only look in this forum for examples and not the other forums with respect to AutoIt integration or relation to Selenium WebDriver.
      So, the example in summary is: you can use Selenium WebDriver API to do AutoIt GUI automation (the ControlXyz() and WinXyz() functons, along with mouse and "send keys" functions). Although I suppose that might be opposite or counter to what most examples here are about - using AutoIt to do or control other stuff rather than using other stuff to control/run AutoIt. But regardless, it is an example implementation of a different use case for AutoIt beyond the general AutoIt community, like those who also use Selenium WebDriver and/or need to integrate Selenium with AutoIt for remote deployment.
      https://github.com/daluu/AutoItDriverServer
      with specific demo examples here:
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/CalculatorTest.java
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/calculator.py
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationTest.java
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationWithAutoItDriver.py
×
×
  • Create New...