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

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
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • 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/ 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/201106-webdriver-udf-help-support-ii/
    • By Langmeister
      I am once again asking for your experienced assistance. If I open a website that uses notifications I am asked to allow or block them for that website after a few seconds. This notification pops up every time the page gets navigated to, even tho you have clicked on allow for several times. I am explicitly not searching for smth to get rid of "Chrome is being controlled by automated test sw". Instead I am searching for a line of script to disable all notifications by default: like here chrome://settings/content/notifications. 
      This is code should give you an example of what notifications I am talking about:
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://webradio.planetradio.de/") _WD_LoadWait($sSession)  
    • By Langmeister
      Hi, I'm sure that this is a simple question regarding webdriver udf but my search on the forum did not result in the exact same scenario that I need. I will adapt it to my corporate needs but at first I want it to work with an example everybody can reproduce if needed.
      I navigate to https://www.daysoftheyear.com/ and want to find out what special day today is. Using the following Code returns the wanted text that today is 'shark awareness day' in the console but it is not pasted in notepad as it is not copied as it probably should be.
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan") _WD_LoadWait($sSession) Sleep(3000) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a") _WD_ElementAction($sSession, $sElement, 'text') ClipGet() Run("notepad.exe") Sleep(500) Send("^v") Scite returns this, therefore the text has been found but the last mile to paste it to notepad or excel does not work for me.
      __WD_Get: URL=HTTP://127.0.0.1:9515/session/b72166b774d7fefb258b3721fc1d4306/element/657e6b5d-31a9-46a8-85c4-acb7f72bf659/text __WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Shark Awareness Day"}... _WD_ElementAction: {"value":"Shark Awareness Day"}... Thanks in advance! 
       
    • By Langmeister
      Hi, I need help performing actions in Salesforce using IE. I used to complete tasks via MouseMove/MouseClick etc. on the Chrome application of SF, but unfortunately this only works for me and not my colleagues due to different positions of things etc. Being unable to get Webdriver UDF or Chromedriver running to interact with the code directly, I chose to look into the IE UDF. ATM I'm trying to tick a specific checkbox in SF which simply allows me to "select all checkboxes" at the same time. Applying the following code on a random website with checkboxes works just fine for me: (in this case selecting cheese checkbox)
      #include <IE.au3> Local $oIE = _IECreate("http://www.echoecho.com/htmlforms09.htm") Local $oSubmit = _IEGetObjByName($oIE, "option3") _IEAction($oSubmit, "click") _IELoadWait($oIE) But applying it to the Salesforce website it does exactly nothing and responds with these warnings/errors:
      The script is exactly the same, except for website and the input name tag of the desired checkbox being different.
      #include <IE.au3> Local $oIE = _IECreate("Corporate Salesforce URL") Local $oSubmit = _IEGetObjByName($oIE, "myPage:myForm:oliListBlock:oliListTable:j_id36") _IEAction($oSubmit, "click") _IELoadWait($oIE) As its working with random websites my guess is that there has to be something done to get it work with SF.
      Hope the more experienced SF+AutoIt pros can help me out here. Thanks in advance!
    • By JohnWIlling
      We are running on a VIrtual Machine via Remote Desktop.  We are having a situation where the loading of the chromedriver.exe is taking longer on the VM than on a physical machine.  It is causing the first call to  WD_Post in _WD_CreateSession to fail.
      To workaround the Issue, I used a simplified version of (_WinAPI_GetTcpTable) UDF to Loop waiting for the driver port to be in the listening state.  At that point, I know that the Post will work:
      Func _WaitForPort($ListenPort) Do Local $tMIB_TCPTABLE = DllStructCreate("dword[6]") Local $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", 0, "BOOL", True) Local $dwSize = $aRet[2] $tMIB_TCPTABLE = DllStructCreate("DWORD[" & $dwSize / 4 & "]") $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", $dwSize, "BOOL", True) If $aRet[0] <> 0 Then Return SetError(1) Local $iNumEntries = DllStructGetData($tMIB_TCPTABLE, 1, 1) Local $aRes[$iNumEntries][6] For $i = 0 To $iNumEntries - 1 Local $Type = DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 0) $aRet = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 2)) ; local port Local $Port = $aRet[0] ConsoleWrite("Checking Row:" & $i & " State:<" & $Type & "> Port:<" & $Port & ">" & @CRLF) ; Type 2 is LISTENING If $Type = 2 And $Port = $ListenPort Then Return 1; EndIF Next Sleep(500); Until 0; Return 0; EndFunc ;==>_WaitForPort  
×
×
  • Create New...