Jump to content

WebDriver UDF (W3C compliant version) - 2024/09/21


Danp2
 Share

Recommended Posts

Hi !

First of all ! Thanks for your great works for this UDF

I have some questions/remarks : 

a ) Can you tell us how to maximise Windows using Firefox Browser ?
    _WD_Window($sSession, "maximize") works very well on chrome but seems not to be working on firefox (I use firefox V52)

b ) Could you tell us how i can get a table content on array
     my goal is to check values on a table and also to click on a specifical line/cell of the table 

I thought that :

$aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//*[@class="MyTable"]/tbody/tr', "", True)

_ArrayDisplay($aElements)


Shows me an array the id element  of all rows but the array is empty

If this is not possible I think it  would be great if you add to the wd_core.au3 library the function getTable($sSession, $Elements, $Separator) returning an array with all lines separated by a separator ( "|" or ";" for example)

 

c) I want to highlight a table with _WD_HighlightElement but it don t seems to work

Thanks for all your helps and answers

Link to comment
Share on other sites

45 minutes ago, danylarson said:

Can you tell us how to maximise Windows using Firefox Browser ?
    _WD_Window($sSession, "maximize") works very well on chrome but seems not to be working on firefox (I use firefox V52)

Can you provide more details, such as results from the UDF and the output from the webdriver console? Also, your version of FF is very old. Please try using the latest version of FF along with the latest version of geckodriver.

47 minutes ago, danylarson said:

Could you tell us how i can get a table content on array
     my goal is to check values on a table and also to click on a specifical line/cell of the table 

I thought that :

$aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//*[@class="MyTable"]/tbody/tr', "", True)

_ArrayDisplay($aElements)


Shows me an array the id element  of all rows but the array is empty

I don't recall trying to retrieve elements from a table, but If the array is empty, then it means that no matching elements were found. If you want us to look into this further, then it would be helpful if you could post a short reproducer script that we can run to observe the issue.

51 minutes ago, danylarson said:

If this is not possible I think it  would be great if you add to the wd_core.au3 library the function getTable($sSession, $Elements, $Separator) returning an array with all lines separated by a separator ( "|" or ";" for example)

This would be best added as a "helper" function to wd_helper.au3. I'll look into this if I have a chance. We also welcome user submissions. :)

54 minutes ago, danylarson said:

I want to highlight a table with _WD_HighlightElement but it don t seems to work

Post a short reproducer script that we can run to observe the issue.

Link to comment
Share on other sites

On 12/15/2018 at 4:19 AM, PaulC said:

Can you add more functions to save the screenshot of web/element?

Here's my rendition of _WD_Screenshot, which will eventually be added to wd_helper.au3. I tried to make it versatile enough for any scenario. I decided to keep it simple by leaving the file writing process to the calling routine.

Note: To test this, you will need to use the latest (unreleased) rendition of wd_core.au3, which can be downloaded here.

#include "wd_core.au3"
#include "wd_helper.au3"
Local $sDesiredCapabilities

Local Enum $eFireFox = 0, _
            $eChrome

Local Const $_TestType = $eFireFox

Func SetupGecko()
_WD_Option('Driver', 'geckodriver.exe')
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)

$sDesiredCapabilities = '{"capabilities":{"alwaysMatch":{"acceptInsecureCerts":true, "pageLoadStrategy":"none"}}}'
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

Switch $_TestType
    Case $eFireFox
        SetupGecko()

    Case $eChrome
        SetupChrome()

EndSwitch

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

If @error <> $_WD_ERROR_Success Then Exit

_WD_Navigate($sSession, "http://www.google.com")
_WD_LoadWait($sSession, 500, 2000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='q']")
$sImage1 = _WD_Screenshot($sSession, $sElement)
$sImage2 = _WD_Screenshot($sSession)
_WD_Navigate($sSession, "http://www.yahoo.com")
_WD_LoadWait($sSession, 500, 2000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@id='uh-signin']")
$sImage3 = _WD_Screenshot($sSession, $sElement)
$sImage4 = _WD_Screenshot($sSession)
_WD_DeleteSession($sSession)

$hImage = FileOpen("image1.png", 18)
FileWrite($hImage, $sImage1)
FileClose($hImage)
$hImage = FileOpen("image2.png", 18)
FileWrite($hImage, $sImage2)
FileClose($hImage)
$hImage = FileOpen("image3.png", 18)
FileWrite($hImage, $sImage3)
FileClose($hImage)
$hImage = FileOpen("image4.png", 18)
FileWrite($hImage, $sImage4)
FileClose($hImage)

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_Screenshot
; Description ...:
; Syntax ........: _WD_Screenshot($sSession[, $sElement = ''[, $nOutputType = 1]])
; Parameters ....: $sSession            - Session ID from _WDCreateSession
;                  $sElement            - [optional] Element ID from _WDFindElement
;                  $nOutputType         - [optional] One of the following output types:
;                               | 1 - String (Default)
;                               | 2 - Binary
;                               | 3 - Base64

; Return values .: None
; Author ........: Dan Pollak
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_Screenshot($sSession, $sElement = '', $nOutputType = 1)
    Local Const $sFuncName = "_WD_Screenshot"
    Local $sResponse, $sJSON, $sResult, $bDecode

    If $sElement = '' Then
        $sResponse = _WD_Window($sSession, 'Screenshot')
        $iErr = @error
    Else
        $sResponse = _WD_ElementAction($sSession, $sElement, 'Screenshot')
        $iErr = @error
    EndIf

    If $iErr = $_WD_ERROR_Success Then
        Switch $nOutputType
            Case 1 ; String
                $sResult = BinaryToString(_Base64Decode($sResponse))

            Case 2 ; Binary
                $sResult = _Base64Decode($sResponse)

            Case 3 ; Base64

        EndSwitch
    Else
        $sResult = ''
    EndIf

    Return SetError(__WD_Error($sFuncName, $iErr), 0, $sResult)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Base64Decode
; Description ...:
; Syntax ........: _Base64Decode($input_string)
; Parameters ....: $input_string        - string to be decoded
; Return values .: Decoded string
; Author ........: trancexx
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://www.autoitscript.com/forum/topic/81332-_base64encode-_base64decode/
; Example .......: No
; ===============================================================================================================================
Func _Base64Decode($input_string)

    Local $struct = DllStructCreate("int")

    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", 0, _
            "int", 1, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", 0, _
            "ptr", 0)

    If @error Or Not $a_Call[0] Then
        Return SetError(1, 0, "") ; error calculating the length of the buffer needed
    EndIf

    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")

    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", 0, _
            "int", 1, _
            "ptr", DllStructGetPtr($a), _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", 0, _
            "ptr", 0)

    If @error Or Not $a_Call[0] Then
        Return SetError(2, 0, ""); error decoding
    EndIf

    Return DllStructGetData($a, 1)

EndFunc   ;==>_Base64Decode

Also, I haven't been able to get the chrome or firefox drivers to successfully return an element image. Please test and share your results here.

Any feedback is appreciated.

Link to comment
Share on other sites

Hmm....

Question: is there a way to Save opened page in google chrome, as pdf file , of course using this UDF ?

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

2 minutes ago, PaulC said:

You can do this by browser's print function

I know, but show me how to do it with this UDF.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

@mLipok What have you tried? Show us your code. :P

Seriously, have you reviewed my prior post with the proposed _WD_Screenshot? Using either that (or by calling the core webdriver function directly) you can capture the page in PNG format. Once you have that, you should be able to use your UDF for Debenu Quick PDF Library to create a PDF containing this image.

Link to comment
Share on other sites

I just answer to @PaulC

Nothing more... for now. 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

22 hours ago, Danp2 said:

Here's my rendition of _WD_Screenshot, which will eventually be added to wd_helper.au3. I tried to make it versatile enough for any scenario. I decided to keep it simple by leaving the file writing process to the calling routine.

Note: To test this, you will need to use the latest (unreleased) rendition of wd_core.au3, which can be downloaded here.

#include "wd_core.au3"
#include "wd_helper.au3"
Local $sDesiredCapabilities

Local Enum $eFireFox = 0, _
            $eChrome

Local Const $_TestType = $eFireFox

Func SetupGecko()
_WD_Option('Driver', 'geckodriver.exe')
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)

$sDesiredCapabilities = '{"capabilities":{"alwaysMatch":{"acceptInsecureCerts":true, "pageLoadStrategy":"none"}}}'
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

Switch $_TestType
    Case $eFireFox
        SetupGecko()

    Case $eChrome
        SetupChrome()

EndSwitch

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

If @error <> $_WD_ERROR_Success Then Exit

_WD_Navigate($sSession, "http://www.google.com")
_WD_LoadWait($sSession, 500, 2000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='q']")
$sImage1 = _WD_Screenshot($sSession, $sElement)
$sImage2 = _WD_Screenshot($sSession)
_WD_Navigate($sSession, "http://www.yahoo.com")
_WD_LoadWait($sSession, 500, 2000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@id='uh-signin']")
$sImage3 = _WD_Screenshot($sSession, $sElement)
$sImage4 = _WD_Screenshot($sSession)
_WD_DeleteSession($sSession)

$hImage = FileOpen("image1.png", 18)
FileWrite($hImage, $sImage1)
FileClose($hImage)
$hImage = FileOpen("image2.png", 18)
FileWrite($hImage, $sImage2)
FileClose($hImage)
$hImage = FileOpen("image3.png", 18)
FileWrite($hImage, $sImage3)
FileClose($hImage)
$hImage = FileOpen("image4.png", 18)
FileWrite($hImage, $sImage4)
FileClose($hImage)

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_Screenshot
; Description ...:
; Syntax ........: _WD_Screenshot($sSession[, $sElement = ''[, $nOutputType = 1]])
; Parameters ....: $sSession            - Session ID from _WDCreateSession
;                  $sElement            - [optional] Element ID from _WDFindElement
;                  $nOutputType         - [optional] One of the following output types:
;                               | 1 - String (Default)
;                               | 2 - Binary
;                               | 3 - Base64

; Return values .: None
; Author ........: Dan Pollak
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_Screenshot($sSession, $sElement = '', $nOutputType = 1)
    Local Const $sFuncName = "_WD_Screenshot"
    Local $sResponse, $sJSON, $sResult, $bDecode

    If $sElement = '' Then
        $sResponse = _WD_Window($sSession, 'Screenshot')
        $iErr = @error
    Else
        $sResponse = _WD_ElementAction($sSession, $sElement, 'Screenshot')
        $iErr = @error
    EndIf

    If $iErr = $_WD_ERROR_Success Then
        Switch $nOutputType
            Case 1 ; String
                $sResult = BinaryToString(_Base64Decode($sResponse))

            Case 2 ; Binary
                $sResult = _Base64Decode($sResponse)

            Case 3 ; Base64

        EndSwitch
    Else
        $sResult = ''
    EndIf

    Return SetError(__WD_Error($sFuncName, $iErr), 0, $sResult)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Base64Decode
; Description ...:
; Syntax ........: _Base64Decode($input_string)
; Parameters ....: $input_string        - string to be decoded
; Return values .: Decoded string
; Author ........: trancexx
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://www.autoitscript.com/forum/topic/81332-_base64encode-_base64decode/
; Example .......: No
; ===============================================================================================================================
Func _Base64Decode($input_string)

    Local $struct = DllStructCreate("int")

    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", 0, _
            "int", 1, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", 0, _
            "ptr", 0)

    If @error Or Not $a_Call[0] Then
        Return SetError(1, 0, "") ; error calculating the length of the buffer needed
    EndIf

    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")

    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", 0, _
            "int", 1, _
            "ptr", DllStructGetPtr($a), _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", 0, _
            "ptr", 0)

    If @error Or Not $a_Call[0] Then
        Return SetError(2, 0, ""); error decoding
    EndIf

    Return DllStructGetData($a, 1)

EndFunc   ;==>_Base64Decode

Also, I haven't been able to get the chrome or firefox drivers to successfully return an element image. Please test and share your results here.

Any feedback is appreciated.

Thank you, I will try and have feedback soon

Link to comment
Share on other sites

On 12/23/2018 at 11:13 PM, Danp2 said:

Here's my rendition of _WD_Screenshot, which will eventually be added to wd_helper.au3. I tried to make it versatile enough for any scenario. I decided to keep it simple by leaving the file writing process to the calling routine.

Note: To test this, you will need to use the latest (unreleased) rendition of wd_core.au3, which can be downloaded here.

#include "wd_core.au3"
#include "wd_helper.au3"
Local $sDesiredCapabilities

Local Enum $eFireFox = 0, _
            $eChrome

Local Const $_TestType = $eFireFox

Func SetupGecko()
_WD_Option('Driver', 'geckodriver.exe')
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)

$sDesiredCapabilities = '{"capabilities":{"alwaysMatch":{"acceptInsecureCerts":true, "pageLoadStrategy":"none"}}}'
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

Switch $_TestType
    Case $eFireFox
        SetupGecko()

    Case $eChrome
        SetupChrome()

EndSwitch

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

If @error <> $_WD_ERROR_Success Then Exit

_WD_Navigate($sSession, "http://www.google.com")
_WD_LoadWait($sSession, 500, 2000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='q']")
$sImage1 = _WD_Screenshot($sSession, $sElement)
$sImage2 = _WD_Screenshot($sSession)
_WD_Navigate($sSession, "http://www.yahoo.com")
_WD_LoadWait($sSession, 500, 2000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@id='uh-signin']")
$sImage3 = _WD_Screenshot($sSession, $sElement)
$sImage4 = _WD_Screenshot($sSession)
_WD_DeleteSession($sSession)

$hImage = FileOpen("image1.png", 18)
FileWrite($hImage, $sImage1)
FileClose($hImage)
$hImage = FileOpen("image2.png", 18)
FileWrite($hImage, $sImage2)
FileClose($hImage)
$hImage = FileOpen("image3.png", 18)
FileWrite($hImage, $sImage3)
FileClose($hImage)
$hImage = FileOpen("image4.png", 18)
FileWrite($hImage, $sImage4)
FileClose($hImage)

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_Screenshot
; Description ...:
; Syntax ........: _WD_Screenshot($sSession[, $sElement = ''[, $nOutputType = 1]])
; Parameters ....: $sSession            - Session ID from _WDCreateSession
;                  $sElement            - [optional] Element ID from _WDFindElement
;                  $nOutputType         - [optional] One of the following output types:
;                               | 1 - String (Default)
;                               | 2 - Binary
;                               | 3 - Base64

; Return values .: None
; Author ........: Dan Pollak
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_Screenshot($sSession, $sElement = '', $nOutputType = 1)
    Local Const $sFuncName = "_WD_Screenshot"
    Local $sResponse, $sJSON, $sResult, $bDecode

    If $sElement = '' Then
        $sResponse = _WD_Window($sSession, 'Screenshot')
        $iErr = @error
    Else
        $sResponse = _WD_ElementAction($sSession, $sElement, 'Screenshot')
        $iErr = @error
    EndIf

    If $iErr = $_WD_ERROR_Success Then
        Switch $nOutputType
            Case 1 ; String
                $sResult = BinaryToString(_Base64Decode($sResponse))

            Case 2 ; Binary
                $sResult = _Base64Decode($sResponse)

            Case 3 ; Base64

        EndSwitch
    Else
        $sResult = ''
    EndIf

    Return SetError(__WD_Error($sFuncName, $iErr), 0, $sResult)
EndFunc

; #FUNCTION# ====================================================================================================================
; Name ..........: _Base64Decode
; Description ...:
; Syntax ........: _Base64Decode($input_string)
; Parameters ....: $input_string        - string to be decoded
; Return values .: Decoded string
; Author ........: trancexx
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://www.autoitscript.com/forum/topic/81332-_base64encode-_base64decode/
; Example .......: No
; ===============================================================================================================================
Func _Base64Decode($input_string)

    Local $struct = DllStructCreate("int")

    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", 0, _
            "int", 1, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", 0, _
            "ptr", 0)

    If @error Or Not $a_Call[0] Then
        Return SetError(1, 0, "") ; error calculating the length of the buffer needed
    EndIf

    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")

    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", 0, _
            "int", 1, _
            "ptr", DllStructGetPtr($a), _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", 0, _
            "ptr", 0)

    If @error Or Not $a_Call[0] Then
        Return SetError(2, 0, ""); error decoding
    EndIf

    Return DllStructGetData($a, 1)

EndFunc   ;==>_Base64Decode

Also, I haven't been able to get the chrome or firefox drivers to successfully return an element image. Please test and share your results here.

Any feedback is appreciated.

Hi Dan,

I tested and have some reviews about _WD_Screenshot:
- Stable operation and returns accurate results
- Capture speed is a bit slow
-
If possible, let the shooting effect be optional


I suddenly thought if you used the HTML DOM .getBoundingClientRect () Method to get the element's boundary and then use GDIPlus UDF to take a screenshot, the result might be better.

Moreover, owning element's boundaries will be very useful in Web automation, Presentation ...
 
 
Edited by PaulC
Link to comment
Share on other sites

Hi Paul,

Appreciate the feedback. I believe all of the items you listed are due to the webdriver implementation and can't be controlled by this UDF. I'm guessing you tested with Chrome, because that's where I also observed the "shooting effect".

As far as getting the element's boundaries, you can use _WD_ElementAction to obtain them.

Dan

Link to comment
Share on other sites

  • 2 weeks later...

Hello, I would like the help to extract the data from a web page, is www.deepl.com, is an automatic translation page.
as my internet is bad I had to keep a copy of the page in my pc and from there by the script I extracted the test data and all well, but when I do it online nothing, I check by development mode in my browser but the data is not stored on the page itself, I think that's why I do not recover the data, the result of the translation the page gets it from a json string from the server, there is some way to get that data using this udf?, another detail would be how to send data to translate, the ideal would be to do it directly from the url but it gives me error apparently because the url exceeds the number of characters, thank you and excuse my ignorance.

#include "wd_core.au3"
#RequireAdmin
Local $sDesiredCapabilities
$_WD_DEBUG = false
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
$usrdatad=StringReplace(@ScriptDir, '\', '\\')&'\\ChromeData'

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["disable-infobars","user-data-dir='&$usrdatad&'"] }}}}'

Local $alltxt = FileReadToArray (@ScriptDir&"\strings.eng.txt"  )

$cantl=0
$cantls=0
$cllimitidx=-1
for $i=0 to UBound($alltxt)-1
    $cantls=StringLen ( $alltxt[$i] )

    if $cantl+$cantls > 4900 then
        $cllimitidx&=','&$i-1
        $cantl=0

    EndIf
    $cantl+=$cantls
Next
$cllimitidx&=','&UBound($alltxt)-1
$cllimitidx=StringSplit($cllimitidx,',',2)
for $i=1 to UBound($cllimitidx)-1
    $catxt=_ArrayToString($alltxt,@CRLF,$cllimitidx[$i-1]+1,$cllimitidx[$i])
$catxt=StringLeft($catxt,198)
Next

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
If $sSession <> "" Then
    _WD_Navigate($sSession, "https://www.deepl.com/translator#en/es/")
;~  _WD_Navigate($sSession, "https://www.deepl.com/translator#en/es/%28Holy%20crap%21%20Mom%E2%80%99s%20ACTUALLY%20fallen%20asleep%20during%20sex%21%29~%0D%0A%28Holy%20crap%21%20Linda%E2%80%99s%20ACTUALLY%20fallen%20asleep%20during%20sex%21%29~%0D%0A%28And%20she%20hasn%E2%80%99t%20even%20gotten%20fully%20undressed%20either.%29~%0D%0A%28Gee%E2%80%A6%20I%20didn%E2%80%99t%20know%20she%20had%20such%20a%20terrible%20sex%20life.%29~%0D%0AAhh%21%20I%E2%80%99m%20cumming%21~%0D%0A%28Uh%20oh%21%20I%20better%20leg%20it%20out%20of%20here%20before%20Dad%20finishes%21%29~%0D%0A%28Uh%20oh%21%20I%20better%20leg%20it%20out%20of%20here%20before%20Bob%20finishes%21%29~%0D%0AIt%27s%20too%20risky.%20I%20should%20leave%20them%20alone.~%0D%0AI%20should%20go%20wash%20the%20dishes.~%0D%0A...are%20in%20a%20high%20speed%20pursuit%20with%20three%20masked%20men.~%0D%0AThe%20vehicle%20was%20stolen%20from%20a%20local%20bank%20parking%20lot.~%0D%0A%28Looks%20like%20Mom%E2%80%99s%20watching%20the%20morning%20news.%29~%0D%0AMorning%2C%20Mom%21~%0D%0A%28Looks%20like%20Linda%E2%80%99s%20watching%20the%20morning%20news.%29~%0D%0AMorning%2C%20Linda%21~%0D%0AGood%20morning%2C%20%5B0%5D.%20Where%20are%20you%20off%20to%3F~%0D%0AIt%E2%80%99s%20a%20school%20day%2C%20remember%3F~%0D%0AOh%21%20Right.~%0D%0AYou%E2%80%99ve%20still%20got%20some%20time.%20Come%20and%20sit%20beside%20me%20for%20a%20while.~%0D%0AUh%2C%20okay.~%0D%0AI%E2%80%99ve%20only%20got%20a%20few%20minutes%20-%20I%20can%E2%80%99t%20stay%20too%20long%2C%20or%20I%E2%80%99ll-~%0D%0AI%20know%20-%20you%E2%80%99ll%20be%20late%20for%20class.~%0D%0AI%E2%80%99m%20going%20to%20teach%20you%20a%20very%20important%20lesson%20right%20now.%20One%20that%20you%20should%20have%20learnt%20YEARS%20ago.~%0D%0ANever%20let%20your%20work%20get%20in%20the%20way%20of%2C%20quality%20family%20time.~%0D%0ANever%20let%20your%20work%20get%20in%20the%20way%20of%2C%20quality%20friendships.~%0D%0AEven%20if%20that%20means%2C%20just%20a%20few%20minutes%20in%20front%20of%20the%20TV%20with%20your%20son%2C%20before%20he%20goes%20to%20school.~%0D%0AEven%20if%20that%20means%2C%20just%20a%20few%20minutes%20in%20front%20of%20the%20TV%20with%20me%2C%20before%20you%20go%20to%20school.~%0D%0AUh%E2%80%A6%20Okay.%20I%E2%80%99ll%20remember%20that.~%0D%0APlease%20do.%20Your%20own%20children%20will%20thank%20you%20for%20it%20someday.~%0D%0A%28Holy%20shit%21%20Mom%E2%80%99s%20not%20wearing%20a%20bra%21%29~%0D%0A%28Holy%20shit%21%20Linda%E2%80%99s%20not%20wearing%20a%20bra%21%29~%0D%0A%28Why%20isn%E2%80%99t%20she%20wearing%20one%3F%21%29~%0D%0A%28She%E2%80%99s%20leaning%20so%20close%20that%20I%20can%20almost%20feel%20her%20left%20nipple%21%29~%0D%0A...and%20I%E2%80%99ll%20never%20make%20that%20mistake%20again.~%0D%0AAre%20you%20listening%2C%20%5B0%5D%3F~%0D%0AHuh%3F%21%20Oh%21%20Y-Yeah%21~%0D%0AHere%2C%20let%20me%20give%20you%20a%20kiss%2C%20before%20you%20rush%20off%20to%20class.~%0D%0A%28Uh%20oh%E2%80%A6%20Is%20she%20going%20to-%29~%0D%0A%28Oh%2C%20it%E2%80%99s%20just%20on%20the%20cheek.%20My%20heart%20started%20racing%20there%21%29~%0D%0A%28Maybe%20I%20am%20over%20analyzing%20things%3F%20Perhaps%20that%20kiss%20before%2C%20was%20her%20being%20a%20loving%20mother%3F%29~%0D%0A%28Maybe%20I%20am%20over%20analyzing%20things%3F%20Perhaps%20that%20kiss%20before%2C%20was%20her%20being%20a%20loving%20friend%3F%29~%0D%0A%28I%E2%80%99ve%20got%20to%20stop%20replaying%20it%20in%20my%20mind.%29~%0D%0A%28Huh%3F%21%20She%E2%80%99s%20turning%20my%20head%21%20This%20ISN%E2%80%99T%20a%20peck%20on%20the%20cheek%21%29~%0D%0A%28What%20should%20I%20do%3F%21%29~%0D%0A%28I%20can%E2%80%99t%20kiss%20her%20back%20like%20this%20-%20she%E2%80%99s%20my%20mother%21%20It%E2%80%99s%20FAR%20too%20intimate%21%29~%0D%0A%28I%20can%E2%80%99t%20kiss%20her%20back%20like%20this%20-%20she%E2%80%99s%20my%20friend%21%20It%E2%80%99s%20FAR%20too%20intimate%21%29~%0D%0A%28She%E2%80%99s%20biting%20my%20lower%20lip%21%29~%0D%0A%28That%E2%80%99s%20it%20-%20any%20chances%20of%20this%20just%20being%20a%20regular%20kiss%20are%20out%20the%20window.%29~%0D%0A%28Oh%20fuck%21%20I%20almost%20did%20it%20again%21%29~%0D%0AI-%20um%E2%80%A6%20I%20have%20to%20rush%20to%20work%20now.%20See%20you%20tonight%21~%0D%0AUh%E2%80%A6%20S-See%20you%20later%2C%20Mom%E2%80%A6~%0D%0AUh%E2%80%A6%20S-See%20you%20later%2C%20Linda%E2%80%A6~%0D%0A%28Maybe%20I%20got%20lucky%2C%20and%20I%20broke%20off%20the%20kiss%20off%20before%20he%20got%20suspicious%3F%29~%0D%0AMorning%2C%20%5B0%5D.~%0D%0AHey%2C%20Mom.~%0D%0AHey%2C%20Linda.~%0D%0AAre%20you%20about%20to%20leave%20for%20school%3F~%0D%0AIn%20a%20few%20minutes%2C%20yeah.~%0D%0ADo%20you%20have%20time%20to%20wash%20a%20few%20dishes%20before%20you%20go%3F~%0D%0AYes~%0D%0ASure%2C%20no%20problem.~%0D%0AThanks%21%20You%E2%80%99re%20a%20sweetie.~%0D%0ANo~%0D%0ASorry%2C%20Mom.%20I%E2%80%99m%20in%20a%20bit%20of%20a%20rush.%20I%20can%E2%80%99t%20afford%20to%20be%20late.~%0D%0ADon%E2%80%99t%20worry%2C%20I%E2%80%99ll%20get%20them%20later.%20Enjoy%20your%20day%21~%0D%0AThanks%2C%20Mom%21~%0D%0ASorry%2C%20Linda.%20I%E2%80%99m%20in%20a%20bit%20of%20a%20rush.%20I%20can%E2%80%99t%20afford%20to%20be%20late.~%0D%0AThanks%2C%20Linda%21~%0D%0AMorning%2C%20Mom%21%20I%E2%80%99m%20heading%20to%20school%20now.~%0D%0AMorning%2C%20Linda%21%20I%E2%80%99m%20heading%20to%20school%20now.~%0D%0AWait%20-%20don%E2%80%99t%20go%20yet%21~%0D%0ASit%20with%20me%20awhile.~%0D%0AI%20don%E2%80%99t%20want%20to%20be%20late.~%0D%0AYou%20won%E2%80%99t%20be%20late%20-%20just%20a%20few%20minutes.~%0D%0ASo%2C%20have%20you%20got%20your%20eye%20on%20any%20girls%20right%20now%3F~%0D%0AI%E2%80%99ve%20seen%20a%20few%20cute%20ones%20around.~%0D%0AI%E2%80%99ve%20seen%20a%20few%20cute%20girls%20about.%20You%20know%20how%20guys%20are.~%0D%0AOooh%2C%20I%20hope%20you%E2%80%99re%20not%20going%20to%20turn%20into%20one%20of%20those%20playboys%20who%20chases%20all%20the%20girls%21%21~%0D%0AHehe%2C%20I%E2%80%99m%20just%20teasing%20you.~%0D%0AYou%20know%20that%20no%20matter%20what%20you%20do%2C%20I%E2%80%99ll%20always%20be%20proud%20of%20my%20boy.~%0D%0AYou%20know%20that%20no%20matter%20what%20you%20do%2C%20I%E2%80%99ll%20always%20be%20proud%20of%20my%20little%20guy.~%0D%0AHaha%21%20You%E2%80%99re%20gonna%20make%20me%20blush%2C%20Mom.~%0D%0AHaha%21%20You%E2%80%99re%20gonna%20make%20me%20blush%2C%20Linda.~%0D%0A%28She%20seems%E2%80%A6%20different%20today.%20I%20wonder%20what%E2%80%99s%20gotten%20into%20her.%29~%0D%0AUmm%E2%80%A6%20Mom%3F~%0D%0AUmm%E2%80%A6%20Linda%3F~%0D%0AUp%20next%20-%20are%20lattes%20making%20you%20fat%3F%20Barry%20McSwindon%20investigates.~%0D%0A%28Slowly%20does%20it%E2%80%A6%20I%E2%80%99m%20going%20to%20move%20my%20hand%2C%20right%20up%20to%20his%20crotch%20and%20see%20how%20he%20reacts.%29~%0D%0AThe%20truth%20is%2C%20Barry%20-%20drinking%20more%20than%20fifty%20lattes%20a%20day%2C%20greatly%20increases%20your%20risk%20of%20obesity.~%0D%0ABut%2C%20Sonja%20-%20who%20the%20hell%20drinks%20fifty%20cups%20of%20coffee%20a%20day%3F%21~%0D%0AThat%E2%80%99s%20not%20the%20point%20I%E2%80%99m%20trying%20to%20make%2C%20Barry.~%0D%0A%28Mom%20looks%20engrossed%20in%20her%20show%E2%80%A6%20I%20don%E2%80%99t%20think%20she%E2%80%99s%20paying%20attention%20to%20what%20she%E2%80%99s%20doing.%29~%0D%0A%28Linda%20looks%20engrossed%20in%20her%20show%E2%80%A6%20I%20don%E2%80%99t%20think%20she%E2%80%99s%20paying%20attention%20to%20what%20she%E2%80%99s%20doing.%29~%0D%0A%28HUH%3F%21%29~%0D%0AA%20typical%20latte%20from%20StarFucks%20has%20190%20calories.%20If%20you%20multiply%20that%20by%20fifty-~%0D%0AJesus%20Fucking%20Christ%2C%20Sonja%21%20You%E2%80%99re%20missing%20the%20point%21~%0D%0AM-Mom%21%20Your%20hand%21~%0D%0AL-Linda%21%20Your%20hand%21~%0D%0AHuh%3F%20Oops%21%20Sorry%2C%20I%20was%20trying%20to%20grab%20your%20arm.%20I%20thought%20you%20had%20it%20resting%20on%20your%20lap.~%0D%0AI%20should%20have%20looked.~%0D%0AWhy%20did%20you%20want%20to%20grab%20my%20arm%3F~%0D%0AHere%2C%20let%20me%20show%20you.~%0D%0ADo%20you%20feel%20that%3F~%0D%0AY-Yeah%20-%20but%20I%20don%E2%80%99t%20think%20I%20should%21~%0D%0AMy%20heartbeat.~%0D%0AOh%21%20R-Right.~%0D%0ADo%20you%20feel%2C%20how%20fast%20it%20beats%20around%20you%3F~%0D%0AIt%E2%80%99s%20only%20around%20you.%20You%E2%80%99re%20special%20to%20me.~%0D%0AM-Mom%E2%80%A6~%0D%0AL-Linda%E2%80%A6~%0D%0AAlways%20remember%20my%20heartbeat%2C%20and%20you%E2%80%99ll%20know%20how%20much%20you%20mean%20to%20me.~%0D%0AI%20really%20do%20love%20you%2C%20%5B0%5D.~%0D%0AI%20will%2C%20Mom.~%0D%0AI%20will%2C%20Linda.")   
Sleep(500)

$sElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, ".lmt__source_textarea")
$sElementt = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, ".lmt__target_textarea")
_WD_ElementAction($sSession, $sElements, 'clear')
_WD_ElementAction($sSession, $sElements, 'value', $catxt)
sleep(5000)
$sText = _WD_ElementAction($sSession, $sElementt, 'text')

ConsoleWrite($sText & @CRLF) ;### Debug Console
Else
    msgbox(0,"","Blank sessionid")
EndIf

;~ _WD_DeleteSession($sSession)
_WD_Shutdown()

 

Edited by dariel
Link to comment
Share on other sites

I am having troubles installing/finding the UDFs. I have the WebDiver-0.1.0.16 zip and the others you said are required. I extracted those .au3s into my include folder but none of them have the core function like

_WD_Startup()

What am I missing? Please help.

I have the chrome, firefox divers installed and the json, winhttp .au3s in my include folder.  

Link to comment
Share on other sites

Hi,

i want to UDF run a javascript from website. This is code from website

<a href="javascript:void(0)" click.delegate="exportToCSV()" class="au-target" au-target-id="461">.csv</a>

My UDF code

_WD_ExecuteScript($sSession, 'exportToCSV();')

but i get error;

_WD_ExecuteScript: {"value":{"error":"unknown error","message":"exportToCSV is not defined\n  (Session info: chrome=71.0.3578.98)","stacktrace":"Backtrace:\n\tOrdinal0 [0x01306650+1533520]\n\tOrdinal0 [0x012750FD+938237]\n\tOrdinal0 [0x012189BF+559551]\n\tOrdinal0 [0x0121A56A+566634]\n\tOrdinal0 [0x0121A454+566356]\n\tOrdinal0 [0x011C39B6+211382]\n\tOrdinal0 [0x011BBA4D+178765]\n\tOrdinal0 [0x011C33E4+209892]\n\tOrdinal0 [0x011BB8EB+178411]\n\tOrdinal0 [0x011A3870+79984]\n\tOrdinal0 [0x011A4D8C+85388]\n\tOrdinal0 [0x011A4CE0+85216]\n\tGetHandleVerifier [0x013BDFF1+573185]\n\tOrdinal0 [0x01316303+1598211]\n\tOrdinal0 [0x013164FD+1598717]\n\tOrdinal0 [0x0131674A+1599306]\n\tOrdinal0 [0x0130E527+1565991]\n\tOrdinal0 [0x0131617F+1597823]\n\tOrdinal0 [0x0128BBEE+1031150]\n\tOrdinal0 [0x01297F2B+1081131]\n\tOrdinal0 [0x0129807A+1081466]\n\tOrdinal0 [0x01297095+1077397]\n\tBaseThreadInitThunk [0x77A88484+36]\n\tRtlAreBitsSet [0x77CC3AB8+136]\n\tRtlAreBitsSet [0x77CC3A88+88]\n"}}
>Exit code: 0    Time: 33.67

 

Can someone explain to me how i want to call this javascript using _WD_ExecuteScript  or any idea execute this javascript?

Link to comment
Share on other sites

28 minutes ago, Danp2 said:

@fagh81 You probably need to prefix it with something like "document." or whatever context the function was originally declared.

. Another way, can i used like below code

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@click.delegate='exportToCSV()']")
_WD_ElementAction($sSession, $sElement, 'Click')

but i got this error

_WD_ElementAction: {"value":{"error":"element not interactable","message":"(Session info: chrome=71.0.3578.98)","stacktrace":"Backtrace:\n\tOrdinal0 [0x01306650+1533520]\n\tOrdinal0 [0x012750FD+938237]\n\tOrdinal0 [0x01218751+558929]\n\tOrdinal0 [0x011AA1AE+106926]\n\tOrdinal0 [0x011A5BB4+89012]\n\tOrdinal0 [0x011BBA4D+178765]\n\tOrdinal0 [0x011A5898+88216]\n\tOrdinal0 [0x011BBCD1+179409]\n\tOrdinal0 [0x011C33E4+209892]\n\tOrdinal0 [0x011BB8EB+178411]\n\tOrdinal0 [0x011A3870+79984]\n\tOrdinal0 [0x011A4D8C+85388]\n\tOrdinal0 [0x011A4CE0+85216]\n\tGetHandleVerifier [0x013BDFF1+573185]\n\tOrdinal0 [0x01316303+1598211]\n\tOrdinal0 [0x013164FD+1598717]\n\tOrdinal0 [0x0131674A+1599306]\n\tOrdinal0 [0x0130E527+1565991]\n\tOrdinal0 [0x0131617F+1597823]\n\tOrdinal0 [0x0128BBEE+1031150]\n\tOrdinal0 [0x01297F2B+1081131]\n\tOrdinal0 [0x0129807A+1081466]\n\tOrdinal0 [0x01297095+1077397]\n\tBaseThreadInitThunk [0x77A88484+36]\n\tRtlAreBitsSet [0x77CC3AB8+136]\n\tRtlAreBitsSet [0x77CC3A88+88]\n"}}
 

How can i want chromedrive to click at this link?

Link to comment
Share on other sites

You only showed the output for the one command, so I have the assume that the prior one was successful. This is a standard Webdriver error, which could be the result of a few things like the link is hidden, disabled, or obscured by another element. Without an example script to run so that we can observe the error, it will be difficult to guide you on how to fix this.

One thing you could try is using Firefox instead of Chrome to rule out an issue with chromedriver.

Link to comment
Share on other sites

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2024/09/21
  • 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
 Share

×
×
  • Create New...