Jump to content

WebDriver UDF (W3C compliant version) - 2023/02/15


Recommended Posts

@Danp2 I have extracted those au3 files, core, helper, and demo. now it gives me this error: 

"C:\Users\a\Desktop\Bots\MyBotScripts\testing_WebDiver.au3"(26,12) : error: _WDStartup(): undefined function.

 

this is my code so far. I am just trying to test it to see if it works. 

;#include "webdriver.au3" Cant find this file?
#include "wd_core.au3"
#include "wd_helper.au3"
#include "wd_demo.au3"

_WDStartup()

 

Link to post
Share on other sites
  • Replies 1k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Latest update just released. See below for change log.  

Latest update just released. See below for change log.  

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 f

Posted Images

@Danp2 Ok I changed it and this is what it gave me: 

Code:

#include "wd_core.au3"
#include "wd_helper.au3"
#include "wd_demo.au3"

_WD_Startup()

Output:

_WDStartup: OS:    WIN_10 WIN32_NT 17134 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.1.0.16
_WDStartup: Driver:    geckodriver.exe
_WDStartup: Params:    --log trace
_WDStartup: Port:    4444
_WD_Startup ==> General Error: Error launching web driver!

 

Then I tried the test code you posted a year ago and this is what that gave me:

Code:

#include "wd_core.au3"
#include "wd_helper.au3"
#include "wd_demo.au3"

Local $aTestSuite[5][2] = [["TestTimeouts", True], ["TestNavigation", True], ["TestElements", True], ["TestScript", True], ["TestCookies", True]]

Local $sDesiredCapabilities
Local $iIndex

Global $_WD__LOCATOR_ByXPath
Global $_WD__ERROR_NoMatch

$_WD__DEBUG = True

Switch $_TestType
    Case $eFireFox
        SetupGecko()

    Case $eChrome
        SetupChrome()

EndSwitch

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)
$sStatus = _WD_Status()

For $iIndex = 0 To UBound($aTestSuite, $UBOUND_ROWS) - 1
    If $aTestSuite[$iIndex][1] Then
        ConsoleWrite("Running: " & $aTestSuite[$iIndex][0] & @CRLF)
        Call($aTestSuite[$iIndex][0])
    Else
        ConsoleWrite("Bypass: " & $aTestSuite[$iIndex][0] & @CRLF)
    EndIf
Next

_WD_DeleteSession($sSession)
_WD_Shutdown()



Func TestTimeouts()
    _WD_Timeouts($sSession)
    _WD_Timeouts($sSession, '{"script":10000,"pageLoad":200000,"implicit":30}')
    _WD_Timeouts($sSession)
EndFunc

Func TestNavigation()
    _WD_Navigate($sSession, "http://google.com")
    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
    _WD_Action($sSession, "back")
    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
    _WD_Action($sSession, "forward")
    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
    ConsoleWrite("Title=" & _WD_Action($sSession, 'title') & @CRLF)
EndFunc

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

Func TestElements()
    _WD_Navigate($sSession, "http://google.com")
    $sElement = _WD_FindElement($sSession, $_WD__LOCATOR_ByXPath, "//input[@id='lst-ib1']")

    If @error = $_WD__ERROR_NoMatch Then
        $sElement = _WD_FindElement($sSession, $_WD__LOCATOR_ByXPath, "//input[@id='lst-ib']")
    EndIf

    $sElement2 = _WD_FindElement($sSession, $_WD__LOCATOR_ByXPath, "//div/input", '', True)

    _WD_ElementAction($sSession, $sElement, 'value', "testing 123")
    _WD_ElementAction($sSession, $sElement, 'text')
    _WD_ElementAction($sSession, $sElement, 'clear')
    _WD_ElementAction($sSession, $sElement, 'value', "abc xyz")
    _WD_ElementAction($sSession, $sElement, 'text')
    _WD_ElementAction($sSession, $sElement, 'clear')
    _WD_ElementAction($sSession, $sElement, 'value', "fujimo")
    _WD_ElementAction($sSession, $sElement, 'text')
    _WD_ElementAction($sSession, $sElement, 'click')

    _WD_ElementAction($sSession, $sElement, 'Attribute', 'test')

    $sElement = _WD_FindElement($sSession, $_WD__LOCATOR_ByXPath, "//input[@id='lst-ib']")
    $sValue = _WD_ElementAction($sSession, $sElement, 'property', 'value')

    ConsoleWrite('value = ' & $sValue & @CRLF)
EndFunc

Func TestScript()
    _WD_ExecuteScript($sSession, 'alert()', "")
    _WD_Alert($sSession, 'Dismiss')
EndFunc

Func TestCookies()
    _WD_Navigate($sSession, "http://google.com")
    _WD_Cookies($sSession, 'Get', 'NID')
EndFunc

Output:

_WDStartup: OS:    WIN_10 WIN32_NT 17134 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.1.0.16
_WDStartup: Driver:    geckodriver.exe
_WDStartup: Params:    --log trace
_WDStartup: Port:    4444
_WD_Startup ==> General Error: Error launching web driver!

Link to post
Share on other sites

@Danp2 Ok so i added the path and this is the new output:

_WDStartup: OS:    WIN_10 WIN32_NT 17134 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.1.0.16
_WDStartup: Driver:    C:\Users\a\Desktop\General help\AutoIt_Stuff\AU3 include files\geckodriver.exe
_WDStartup: Params:    --log trace
_WDStartup: Port:    4444
__WD_Post: URL=HTTP://127.0.0.1:4444/session; $sData={"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}
__WD_Post: StatusCode=500; ResponseText={"value":{"error":"session not created","message":"Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line","stacktrace":""}}
_WD_CreateSession: {"value":{"error":"session not created","message":"Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line","stacktrace":""}}
_WD_CreateSession ==> Webdriver Exception: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
__WD_Delete: URL=HTTP://127.0.0.1:4444/session/
__WD_Delete: StatusCode=404; ResponseText={"value":{"error":"unknown command","message":"DELETE /session/ did not match a known command","stacktrace":""}}
_WD_DeleteSession: {"value":{"error":"unknown command","message":"DELETE /session/ did not match a known command","stacktrace":""}}

 

Code: I ran the demo code 

#include "wd_core.au3"
#include "wd_helper.au3"

Local Enum $eFireFox = 0, _
            $eChrome, _
            $eEdge

Local $aDemoSuite[][2] = [["DemoTimeouts", False], _
                        ["DemoNavigation", False], _
                        ["DemoElements", True], _
                        ["DemoScript", False], _
                        ["DemoCookies", False], _
                        ["DemoAlerts", False], _
                        ["DemoFrames", False], _
                        ["DemoActions", False], _
                        ["DemoWindows", False]]

Local Const $_TestType = $eFireFox
Local Const $sElementSelector = "//input[@name='q']"

Local $sDesiredCapabilities
Local $iIndex
Local $sSession

$_WD_DEBUG = $_WD_DEBUG_Info

Switch $_TestType
    Case $eFireFox
        SetupGecko()

    Case $eChrome
        SetupChrome()

    Case $eEdge
        SetupEdge()

EndSwitch

_WD_Startup()

If @error <> $_WD_ERROR_Success Then
    Exit -1
EndIf

$sSession = _WD_CreateSession($sDesiredCapabilities)

If @error = $_WD_ERROR_Success Then
    For $iIndex = 0 To UBound($aDemoSuite, $UBOUND_ROWS) - 1
        If $aDemoSuite[$iIndex][1] Then
            ConsoleWrite("Running: " & $aDemoSuite[$iIndex][0] & @CRLF)
            Call($aDemoSuite[$iIndex][0])
        Else
            ConsoleWrite("Bypass: " & $aDemoSuite[$iIndex][0] & @CRLF)
        EndIf
    Next
EndIf

_WD_DeleteSession($sSession)
_WD_Shutdown()


Func DemoTimeouts()
    _WD_Timeouts($sSession)
    _WD_Timeouts($sSession, '{"pageLoad":2000}')
    _WD_Timeouts($sSession)
EndFunc

Func DemoNavigation()
    _WD_Navigate($sSession, "http://google.com")
    _WD_NewTab($sSession)
    _WD_Navigate($sSession, "http://yahoo.com")
    _WD_NewTab($sSession)
    _WD_Navigate($sSession, "http://bing.com")

    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
    _WD_Attach($sSession, "google.com", "URL")
    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
    _WD_Attach($sSession, "yahoo.com", "URL")
    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
EndFunc

Func DemoElements()
    Local $sElement, $aElements, $sValue

    _WD_Navigate($sSession, "http://google.com")
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='q1']")

    If @error = $_WD_ERROR_NoMatch Then
        $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sElementSelector)
    EndIf

    $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div/input", '', True)

    _ArrayDisplay($aElements)

    _WD_ElementAction($sSession, $sElement, 'value', "testing 123")
    Sleep(500)

    _WD_ElementAction($sSession, $sElement, 'text')
    _WD_ElementAction($sSession, $sElement, 'clear')
    Sleep(500)
    _WD_ElementAction($sSession, $sElement, 'value', "abc xyz")
    Sleep(500)
    _WD_ElementAction($sSession, $sElement, 'text')
    _WD_ElementAction($sSession, $sElement, 'clear')
    Sleep(500)
    _WD_ElementAction($sSession, $sElement, 'value', "fujimo")
    Sleep(500)
    _WD_ElementAction($sSession, $sElement, 'text')
    _WD_ElementAction($sSession, $sElement, 'click')

    $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='btnK']")
    ConsoleWrite("Button Ref: " & $sButton & @CRLF)
    ConsoleWrite("Before Click" & @CRLF)
    _WD_ElementAction($sSession, $sButton, 'click')    ;<
    Sleep(2000)
    ConsoleWrite("After Click" & @CRLF)

    _WD_ElementAction($sSession, $sElement, 'Attribute', 'text')

    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sElementSelector)
    $sValue = _WD_ElementAction($sSession, $sElement, 'property', 'value')

    ConsoleWrite('value = ' & $sValue & @CRLF)

EndFunc

Func DemoScript()
    _WD_ExecuteScript($sSession, "return arguments[0].second;", '{"first": "1st", "second": "2nd", "third": "3rd"}')
    _WD_Alert($sSession, 'Dismiss')
EndFunc

Func DemoCookies()
    _WD_Navigate($sSession, "http://google.com")
    _WD_Cookies($sSession, 'Get', 'NID')

    Local $sName = "Testname"
    Local $sValue ="TestValue"
    Local $sCookie = '{"cookie": {"name":"' & $sName & '","value":"' & $sValue & '"}}'
    _WD_Cookies($sSession, 'add', $sCookie)
    _WD_Cookies($sSession, 'Get', $sName)
EndFunc

Func DemoAlerts()
    ConsoleWrite('Alert Detected => ' & _WD_Alert($sSession, 'status') & @CRLF)
    _WD_ExecuteScript($sSession, "alert('testing 123')")
    ConsoleWrite('Alert Detected => ' & _WD_Alert($sSession, 'status') & @CRLF)
    ConsoleWrite('Text Detected => ' & _WD_Alert($sSession, 'gettext') & @CRLF)
    _WD_Alert($sSession, 'sendtext', 'new text')
    ConsoleWrite('Text Detected => ' & _WD_Alert($sSession, 'gettext') & @CRLF)
    Sleep(5000)
    _WD_Alert($sSession, 'Dismiss')

EndFunc

Func DemoFrames()
    _WD_Navigate($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_frame_cols")
    ConsoleWrite("Frames=" & _WD_GetFrameCount($sSession) & @CRLF)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='iframeResult']")
    _WD_FrameEnter($sSession, $sElement)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
    _WD_FrameLeave($sSession)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)

EndFunc

Func DemoActions()
    Local $sElement, $aElements, $sValue

    _WD_Navigate($sSession, "http://google.com")
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sElementSelector)

ConsoleWrite("$sElement = " & $sElement & @CRLF)

    $sAction = '{"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"'
    $sAction &= $sElement & '","' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}},{"button":2,"type":"pointerDown"},{"button":2,"type":"pointerUp"}]}]}'

ConsoleWrite("$sAction = " & $sAction & @CRLF)

    _WD_Action($sSession, "actions", $sAction)
    sleep(5000)
    _WD_Action($sSession, "actions")
    sleep(5000)
EndFunc

Func DemoWindows()
    Local $sResponse, $sResult, $sJSON, $sImage

    _WD_Navigate($sSession, "http://google.com")
    $sResponse = _WD_Window($sSession, 'screenshot')
    $sJSON = Json_Decode($sResponse)
    $sResult = Json_Get($sJSON, "[value]")

    $sImage = BinaryToString(base64($sResult, False))
    ConsoleWrite($sImage & @CRLF)

EndFunc

Func SetupGecko()
_WD_Option('Driver', 'C:\Users\a\Desktop\General help\AutoIt_Stuff\AU3 include files\geckodriver.exe')
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)

$sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
EndFunc

Func SetupChrome()
_WD_Option('Driver', 'C:\Users\a\Desktop\General help\AutoIt_Stuff\AU3 include files\chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}'
EndFunc

Func SetupEdge()
_WD_Option('Driver', 'MicrosoftWebDriver.exe')
_WD_Option('Port', 17556)
_WD_Option('DriverParams', '--verbose')

$sDesiredCapabilities = '{"capabilities":{}}'
EndFunc

;==============================================================================================================================
; Function:         base64($vCode [, $bEncode = True [, $bUrl = False]])
;
; Description:      Decode or Encode $vData using Microsoft.XMLDOM to Base64Binary or Base64Url.
;                   IMPORTANT! Encoded base64url is without @LF after 72 lines. Some websites may require this.
;
; Parameter(s):     $vData      - string or integer | Data to encode or decode.
;                   $bEncode    - boolean           | True - encode, False - decode.
;                   $bUrl       - boolean           | True - output is will decoded or encoded using base64url shema.
;
; Return Value(s):  On Success - Returns output data
;                   On Failure - Returns 1 - Failed to create object.
;
; Author (s):       (Ghads on Wordpress.com), Ascer
;===============================================================================================================================
Func base64($vCode, $bEncode = True, $bUrl = False)

    Local $oDM = ObjCreate("Microsoft.XMLDOM")
    If Not IsObj($oDM) Then Return SetError(1, 0, 1)

    Local $oEL = $oDM.createElement("Tmp")
    $oEL.DataType = "bin.base64"

    If $bEncode then
        $oEL.NodeTypedValue = Binary($vCode)
        If Not $bUrl Then Return $oEL.Text
        Return StringReplace(StringReplace(StringReplace($oEL.Text, "+", "-"),"/", "_"), @LF, "")
    Else
        If $bUrl Then $vCode = StringReplace(StringReplace($vCode, "-", "+"), "_", "/")
        $oEL.Text = $vCode
        Return $oEL.NodeTypedValue
    EndIf

EndFunc ;==>base64

 

Edited by nooneclose
Link to post
Share on other sites
7 minutes ago, nooneclose said:

__WD_Post: StatusCode=500; ResponseText={"value":{"error":"session not created","message":"Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line","stacktrace":""}}

It can't find FireFox. If you've installed it to a non-default location, then it is your responsibility to provide it with the correct path. I believe there is an example of this in either this thread or the one for Webdriver support.

Link to post
Share on other sites

I want to create a session (chrome website) which playing a video.

After that i have another script  that run regularly in the background to do somethings on an existing session (such as volume adjustment..)

For some reasons i cant re-open the website every time i want to adjust the volume so that i have to separate  into 2 scripts.

My solution is to write the session id to a text file and read it every time i want to control this session.

Are there any better solutions to handle this problem?

Many thanks.

Link to post
Share on other sites
55 minutes ago, chadkin2019 said:

My solution is to write the session id to a text file and read it every time i want to control this session.

That's one solution. Other options would be --

  • Passing the session id as a parameter to the 2nd script
  • Use IPC to pass the session id between scripts
  • Combine everything into a single script that remains running in the background
Link to post
Share on other sites

Hi  Dan,

I asked some question for tables and you asked me for some example

1) I wanted to highlight a table and it does not seem to works properly in my examples

2)  i coded the function  _WD_GetTableContent($sSession, $aElements, $Separator)

I think you can add this fonction to your library (and if you want improve it, you ll welcome :D )


Thanks for your help and answer

Test.html

GetTable.au3

Link to post
Share on other sites

Hi,

Can anyone help me.

 

in html page i have two html code

<button class="applyBtn btn btn-sm btn-success" disabled="disabled" type="button">Apply</button>

and other one

<button class="applyBtn btn btn-sm btn-success"  type="button">Apply</button>

 The button is control by javascript to show the disable one or not

 

How can i want the UDF click this butto when it was enable?. This is my code

$sElement222 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='applyBtn btn btn-sm btn-success']")
_WD_ElementAction($sSession, $sElement222, 'click')

Are this UDF can click the seconds enable button, hope anybody can help me.

 

Edited by fagh81
Link to post
Share on other sites

Hello,

i get the following error:

 

__WD_Post: URL=HTTP://127.0.0.1:9515/session/60735297ef5fae98bfc3aa4ceeb83dce/element/2e066b85-ddef-4ace-919d-c858e50b5700/value; $sData={"id":"2e066b85-ddef-4ace-919d-c858e50b5700", "text":"temp"}
__WD_Post: StatusCode=500; ResponseText={"value":{"error":"unknown error","message":"'value' must be a list(Session infochrome=71.0.3578.98)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0107AA90+830096]\n\tOrdinal0 [0x0102581D+481309]\n\tOrdinal0 [0x00FFAC47+306247]\n\tOrdinal0 [0x00FC5DB1+89521]\n\tOrdinal0 [0x00FDAA9D+174749]\n\tOrdinal0 [0x00FC4E28+85544]\n\tOrdinal0 [0x00FDAD31+175409]\n\tOrdinal0 [0x00FE208B+204939]\n\tOrdinal0 [0x00FDA93B+174395]\n\tOrdinal0 [0x00FC2D54+77140]\n\tOrdinal0 [0x00FC430C+82700]\n\tOrdinal0 [0x00FC4260+82528]\n\tOrdinal0 [0x01085302+873218]\n\tOrdinal0 [0x01030553+525651]\n\tOrdinal0 [0x01030783+526211]\n\tOrdinal0 [0x0103086C+526444]\n\tOrdinal0 [0x010883A7+885671]\n\tOrdinal0 [0x010303BF+525247]\n\tOrdinal0 [0x0103A60E+566798]\n\tOrdinal0 [0x01045DDB+613851]\n\tOrdinal0 [0x01045F45+614213]\n\tOrdinal0 [0x01045175+610677]\n\tBaseThreadInitThunk [0x74F08484+36]\n\tRtlAreBitsSet [0x77573AB8+136]\n\tRtlAreBitsSet [0x77573A88+88]\n"}}
_WD_ElementAction: {"value":{"error":"unknown error","message":"'value' must be a list(Session infochrome=71.0.3578.98)...
_WD_ElementAction ==> Webdriver Exception: {"value":{"error":"unknown error","message":"'value' must be a list(Session infochrome=71.0.3578.98)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0107AA90+830096]\n\tOrdinal0 [0x0102581D+481309]\n\tOrdinal0 [0x00FFAC47+306247]\n\tOrdinal0 [0x00FC5DB1+89521]\n\tOrdinal0 [0x00FDAA9D+174749]\n\tOrdinal0 [0x00FC4E28+85544]\n\tOrdinal0 [0x00FDAD31+175409]\n\tOrdinal0 [0x00FE208B+204939]\n\tOrdinal0 [0x00FDA93B+174395]\n\tOrdinal0 [0x00FC2D54+77140]\n\tOrdinal0 [0x00FC430C+82700]\n\tOrdinal0 [0x00FC4260+82528]\n\tOrdinal0 [0x01085302+873218]\n\tOrdinal0 [0x01030553+525651]\n\tOrdinal0 [0x01030783+526211]\n\tOrdinal0 [0x0103086C+526444]\n\tOrdinal0 [0x010883A7+885671]\n\tOrdinal0 [0x010303BF+525247]\n\tOrdinal0 [0x0103A60E+566798]\n\tOrdinal0 [0x01045DDB+613851]\n\tOrdinal0 [0x01045F45+614213]\n\tOrdinal0 [0x01045175+610677]\n\tBaseThreadInitThunk [0x74F08484+36]\n\tRtlAreBitsSet [0x77573AB8+136]\n\tRtlAreBitsSet [0x77573A88+88]\n"}}

with this code:

 

#include "wd_core.au3"
#include "wd_helper.au3"

Local $sSession, $sDesiredCapabilities
SetupChrome()

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
StartRegistration()
_WD_Shutdown()

Func StartRegistration()
   _WD_Navigate($sSession, "https://www.dazn.com/de-DE")
   _WD_LoadWait($sSession)
   _WD_Navigate($sSession, "https://www.dazn.com/de-DE/account/signup")
   _WD_LoadWait($sSession)
   $firstName = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='firstName']")
   _WD_ElementAction($sSession, $firstName , 'value', "temp")
EndFunc

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

 

I just want to fill in some value into the firstname field, but i always get the error: value must be a list.

 

Can someone help me?

Link to post
Share on other sites

@Lunier What version Chrome? Chromedriver? Also, what version of the UDF?

FWIW, I'm not seeing this same error. I did modify your StartRegistration function as follows to deal with the opening animation --

Func StartRegistration()
   _WD_Navigate($sSession, "https://www.dazn.com/de-DE/account/signup")
   _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='firstName']")

   $firstName = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='firstName']")
   _WD_ElementAction($sSession, $firstName , 'value', "temp")
EndFunc

 

Link to post
Share on other sites
  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2023/02/15
  • Melba23 pinned this topic

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Blaxxun
      Hello,
      I open a new thread here since i dont want to hijack the thread of @water  called "I'm creating a WebDriver tutorial".
      As recommended i started to take a deeper look into the "GDPR fines.au3" example.
      I also fount that "au3WebDriver-0.11.0" comes with a nice Help file "Webdriver.chm"
      When running GDPR fines.au3 i noticed that it uses a function called:
      _WD_GetTable($sSession, $sBaseElement, $iPage)
      It has 3 function parameters and is IN the "GDPR fines.au3"

      So i got an error: wrong number of args.
      Further investigation showed me that this function is already defined in the "wd_helper.au3" which is loaded at the beginnings #include but has only 2 parameters.
      So i commented out the function in the "wd_helper.au3"

      The _WD_GetTable function ran error free now but the next stop was:
      _WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='penalties_length']//option[contains(text(),'" & $aOptions[UBound($aOptions, 1) - 2] & "')]")
      Variable subscript badly formatted (Error at -> UBound)
       
      I'm not really sure why this happens because i dont really know how to traverse a website yet.
      Have to dig deeper and read into it more.
    • By corvo
      Hello!

      I've been trying to launch chrome through WD,  but for some reason, the user profile is not working, it just opens up the chrome window with the "temp" user. I've also made sure that the user profile path is correct by using "chrome://version". 
      Here is what I've got so far:
      #include "wd_helper.au3" #include "wd_capabilities.au3" #include "wd_core.au3" SetupChrome() _WD_CapabilitiesStartup() Local $sCapabilities = _WD_CapabilitiesGet() $sSession = _WD_CreateSession($sCapabilities) _WD_Navigate($sSession, "https://www.google.com") Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') _WD_Option('DriverParams', '--marionette-port 2828') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Google\\Chrome\\User Data\\", "--profile-directory=Profile 2"]}}}}' $_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error EndFunc  
      Thanks in advance!
       
    • By ThomasBennett
      Good morning, everyone, 
      I have had very good luck with using _WD_ElementActionEx 'CLICKANDHOLD'. What would be the best practice with dragging and dropping web elements? I would prefer to not to have to use any dragging and dropping but I haven't figured out a way to change the order the elements are displayed programmatically. 
      I have a list of elements that are drag and drop. These elements in code are using <UL></UL> for the entire list and the actual web elements that are being manipulated are in <LI></LI> tags. These do not look like a bulleted list but that is the code that is being used. I've spoken with the web developer and there isn't any hot keys or keyboard commands that can be used to move these elements.
      I know where the new and original web element appears and can select them using the _WD_WaitElement and _WD_FindElement combo. I can find the number of items in the list by looking at the code; I haven't started pulling the values out just yet. I am trying to figure out if there is a place to change the listed order.
      Using the 'CLICKANDHOLD' feature as part of _WD_ElementActionEx does work and I know more or less where I need to drop it the new web element; the problem I am having is scrolling exactly to where I need the new web element dropped. It should be dropped beneath the original web element. 
      What's the best method to output the number of children associated with the <UL></UL>? I am guessing that _WD_ElementActionEx 'CHILDCOUNT' would be it; but I haven't figured out how to get the call to output in a msgbox or in the console. 
      #cs ---------------------------------------------------------------- Name ..........: Please Note!.au3 Description ...: To be used to add new lessons to existing playlists and to update the pre-existing lesson with the Please Note! PowerPoint SciTE 32-bit ..: Version 4.4.6 Author(s) .....: Thomas E. Bennett Date ..........: 20220929 Recommended Reading / Requirements https://www.autoitscript.com/forum/topic/191990-webdriver-udf-w3c-compliant-version-01162021/#comments https://www.autoitscript.com/wiki/WebDriver https://www.autoitscript.com/wiki/WebDriver#Installation https://www.autoitscript.com/wiki/Adding_UDFs_to_AutoIt_and_SciTE https://www.autoitscript.com/autoit3/docs/intro/running.htm#CommandLine wd_core.au3 wd_helper.au3 From wd_core.au3 Global Const $_WD_LOCATOR_ByCSSSelector = "css selector" Global Const $_WD_LOCATOR_ByXPath = "xpath" Global Const $_WD_LOCATOR_ByLinkText = "link text" Global Const $_WD_LOCATOR_ByPartialLinkText = "partial link text" Global Const $_WD_LOCATOR_ByTagName = "tag name" #ce ---------------------------------------------------------------- #include "wd_core.au3" #include "wd_helper.au3" #include <MsgBoxConstants.au3> #include <Excel.au3> #include <AutoItConstants.au3> Local $sDesiredCapabilities, $sSession, $sElement ; Create application object and open an example workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\{PRIVACY}.xlsx") If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error opening workbook '" & @ScriptDir & "\{PRIVACY}.xlsx'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; Read data from a single cell on the active sheet of the specified workbook ;Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A1") ;If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 1", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 1", "Data successfully read." & @CRLF & "Value of cell A1: " & $sResult) SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) Sleep (15000) Local $aResult = _Excel_RangeRead($oWorkbook, Default, "A16:E16") For $i = 0 To UBound($aResult, 1) - 1 ;ConsoleWrite("========= Start Row =========" & @CRLF) ;ConsoleWrite($aResult[$i][0] & @CRLF) ; Column A -- Course Playlist Number ;ConsoleWrite($aResult[$i][1] & @CRLF) ; Column B -- Course Playlist Title ;ConsoleWrite($aResult[$i][2] & @CRLF) ; Column C -- Original Lesson Title ;ConsoleWrite($aResult[$i][3] & @CRLF) ; Column D -- Updated Lesson Number ;ConsoleWrite($aResult[$i][4] & @CRLF) ; Column E -- Updated Lesson Title ;ConsoleWrite("========= End Row =========" & @CRLF & @CRLF) _WD_Navigate($sSession, "{PRIVACY}" & $aResult[$i][0]) _WD_LoadWait($sSession, 2000) ; Find the Available Lessons search box and enter the appropriate value _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='titleSearch']") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='titleSearch']") ; Click the Sign in button _WD_ElementAction($sSession, $sElement, 'value', $aResult[$i][3]) Send("{Enter}") ; Find the correct "Add" hyperlink _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//span[text()='" & $aResult[$i][4] & "']/following-sibling::div") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[text()='" & $aResult[$i][4] & "']/following-sibling::div") ; Click the "Add" hyperlink _WD_ElementAction($sSession, $sElement, 'click') ; Number of Child Elements _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']") _WD_ElementActionEx($sSession, $sElement, 'CHILDCOUNT') Exit ; Click and Hold the appropriate element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/parent::li") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/parent::li") _WD_ElementActionEx($sSession, $sElement, 'clickandhold', 0, 0, 0, 10000) ; Hover the appropriate element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/following-sibling::a") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/following-sibling::a") _WD_ElementActionEx($sSession, $sElement, 'HOVER') Exit Next Exit _WD_DeleteSession($sSession) _WD_Shutdown() Exit Func SetupChrome() ; Google Chrome _WD_Option('Driver', "C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe") _WD_Option('Port', 9515) ;_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"unhandledPromptBehavior": "ignore", ' & _ '"goog:chromeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"], "useAutomationExtension": false, ' & _ '"prefs": {"credentials_enable_service": false},' & _ '"args": ["start-maximized"] }}}}' EndFunc Console Output
      >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\thomas.bennett\Desktop\AutoIt\Please Note!\Please Note!.au3" /UserParams +>09:22:40 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_10/2009 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\thomas.bennett\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\thomas.bennett\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\thomas.bennett\Desktop\AutoIt\Please Note!\Please Note!.au3 +>09:22:40 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\thomas.bennett\Desktop\AutoIt\Please Note!\Please Note!.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. _WD_Option ==> Success [0] : Parameters: Option=Driver Value=C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe _WD_Option ==> Success [0] : Parameters: Option=Port Value=9515 _WD_IsLatestRelease ==> Success [0] : True _WD_Startup: OS: WIN_10 WIN32_NT 22000 _WD_Startup: AutoIt: 3.3.14.5 _WD_Startup: Webdriver UDF: 0.10.1 (Up to date) _WD_Startup: WinHTTP: 1.6.4.2 _WD_Startup: Driver: C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe (32 Bit) _WD_Startup: Params: _WD_Startup: Port: 9515 _WD_Startup: Command: "C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe" _WD_Startup ==> Success [0] __WD_Post ==> Success [0] : HTTP status = 200 _WD_CreateSession ==> Success [0] : 2542b35e47b8f9b2558cd92ad1418811 __WD_Post ==> Success [0] : HTTP status = 200 _WD_Navigate ==> Success [0] : Parameters: URL={PRIVACY} _WD_LoadWait ==> Success [0] : Parameters: Delay=2000 Timeout=Default Element=Default _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Username'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Username'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=value Option=<masked> _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Password'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Password'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=value Option=<masked> _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@value='Sign In'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@value='Sign In'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=click Option=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_Navigate ==> Success [0] : Parameters: URL={PRIVACY} _WD_LoadWait ==> Success [0] : Parameters: Delay=2000 Timeout=Default Element=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_Navigate ==> Success [0] : Parameters: URL={PRIVACY} _WD_LoadWait ==> Success [0] : Parameters: Delay=2000 Timeout=Default Element=Default _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='titleSearch'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='titleSearch'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=value Option=<masked> _WD_WaitElement ==> Timeout [7] : Parameters: Strategy=xpath Selector=//span[text()='{PRIVACY}']/following-sibling::div Delay=Default Timeout=Default Options=Default __WD_Post ==> No match [8] : HTTP status = 404 _WD_FindElement ==> No match [8] : Parameters: Strategy=xpath Selector=//span[text()='{PRIVACY}']/following-sibling::div StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=click Option=Default _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//ul[@id='selected-items'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//ul[@id='selected-items'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ExecuteScript ==> Success [0] _WD_ElementActionEx ==> Success [0] : Parameters: Element=21c01052-8b86-4058-b8f6-d9dfa750f9ee Command=CHILDCOUNT XOffset=Default YOffset=Default Button=Default HoldDelay=Default Modifier=Default +>09:23:20 AutoIt3.exe ended.rc:0 +>09:23:20 AutoIt3Wrapper Finished. >Exit code: 0 Time: 40.88  

      My thought is once AutoIt knows how many child elements there are; I am hoping that there would be a way to change the sort or priority order that the <LI></LI>'s are shown in. 
      Thank you for your time and efforts on this and as I progress I'll update this topic, 




      Thomas 
    • By ThomasBennett
      #cs ---------------------------------------------------------------- Name ..........: ignore.au3 Description ...: Testing _WD_HighlightElements SciTE 32-bit ..: Version 4.4.6 Author(s) .....: Thomas E. Bennett Date ..........: 20220929 Recommended Reading / Requirements https://www.autoitscript.com/forum/topic/191990-webdriver-udf-w3c-compliant-version-01162021/#comments https://www.autoitscript.com/wiki/WebDriver https://www.autoitscript.com/wiki/WebDriver#Installation https://www.autoitscript.com/wiki/Adding_UDFs_to_AutoIt_and_SciTE https://www.autoitscript.com/autoit3/docs/intro/running.htm#CommandLine wd_core.au3 wd_helper.au3 From wd_core.au3 Global Const $_WD_LOCATOR_ByCSSSelector = "css selector" Global Const $_WD_LOCATOR_ByXPath = "xpath" Global Const $_WD_LOCATOR_ByLinkText = "link text" Global Const $_WD_LOCATOR_ByPartialLinkText = "partial link text" Global Const $_WD_LOCATOR_ByTagName = "tag name" #ce ---------------------------------------------------------------- #include "wd_core.au3" #include "wd_helper.au3" #include "wd_cdp.au3" #include "wd_capabilities.au3" #include <MsgBoxConstants.au3> Local $sDesiredCapabilities, $sElement, $sSession Func SetupChrome() ; Google Chrome _WD_Option('Driver', @ScriptDir & "\include\chromedriver.exe") _WD_Option('Port', 9515) ;_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"unhandledPromptBehavior": "ignore", ' & _ '"goog:chromeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"], "useAutomationExtension": false, ' & _ '"prefs": {"credentials_enable_service": false},' & _ '"args": ["start-maximized"] }}}}' EndFunc SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) Sleep (15000) ; DuckDuckGo _WD_Navigate($sSession, "https://duckduckgo.com/") _WD_LoadWait($sSession, 2000) ; Find the Search field _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='search_form_input_homepage']") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='search_form_input_homepage']") ; Highlight the Search field _WD_HighlightElements($sSession, $sElement, 3) MsgBox(0,"","") Exit ;this is here on purpose _WD_DeleteSession($sSession) _WD_Shutdown() Exit Good evening, everyone, 
      I am trying to get any element to highlight using the _WD_HighlightElements function; I've tried different elements and for a time I thought maybe because I am working in Windows 11 so I switched back to Windows 10 same issue; I can't get the found element to highlight. What am I doing incorrectly?
      Console Output _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"0e212d4f-8437-42a0-a56a-bc8694fe6e66"}} _WD_WaitElement ==> Success __WD_Post: URL=HTTP://127.0.0.1:9515/session/0e05f8ea99dba06bb84908b0b46fe881/element; $sData={"using":"xpath","value":"//input[@id='search_form_input_homepage']"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"0e212d4f-8437-42a0-a56a-bc8694fe6e66"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"0e212d4f-8437-42a0-a56a-bc8694fe6e66"}} Thank you for your time on this,




      Thomas E. Bennett
    • By SkysLastChance
      I am having trouble finding a good way to click these "button" below. 

      I only need to be able to click them when they have both yes/no. Otherwise I don't have to worry about them. For instance if they looked like this I would NOT have worry about clicking them and can just ignore them all togheter.(Below Picture)

      The problem is as mentioned in the title, all of the ID's  are dynamic. (Classes too)

      Here is what it looks like if yes is already selected.

      This is what I was using to select the the button. However, I need to know if the button has already been clicked/selected or not.
      _WD_LoadWait($sSession) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[text() = 'Offered access to electronic health information?']") Sleep(1000) _WD_ElementAction($sSession, $sElement, 'click') Sleep(500) _WD_Action($sSession, "actions", $sActionTab) Sleep(500) _WD_Action($sSession, "actions", $sActionEnter) Is there a way I can get the count of spans in the span class-"s_636" by tabbing over to the button? I am hoping someone might have some ideas on what I can try.
      Unfortunally, The site is for work so giving the site wont do any good. 
×
×
  • Create New...