Jump to content

WebDriver UDF - Help & Support (III)


Danp2
 Share

Recommended Posts

36 minutes ago, Danp2 said:

Ideally, the solution would be a generic "builder" for the Desired Capabilities that wouldn't require a separate function for each "action".

Do you mean something like this:

Func _Example2()
    Local $a_WD_CAP
    _WD_Capabilities_Add($a_WD_CAP, $_WD_CAP_GECKO_OPTION_BINARY, 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
    _WD_Capabilities_Add($a_WD_CAP, $_WD_CAP_GECKO_OPTION_LOGLEVEL, 'trace')
    _WD_Capabilities_Add($a_WD_CAP, $_WD_CAP_GECKO_OPTION_ARGS, '-profile', 'C:\Users\agatk\AppData\Roaming\Mozilla\Firefox\Profiles\5819ktj7.default')

    Local $sDesiredCapabilities = _WD_Capabilities_Create($a_WD_CAP)
    Return $sDesiredCapabilities
EndFunc   ;==>_Example2

?

or even better this way:

_Example3()

Func _Example3()
    ; .......
    Local $s_Desired_Capabilities = _My_Chrome_Capabilities()
    ; .......
EndFunc   ;==>_Example3

Func _My_Chrome_Capabilities()
    _WD_Capabilities_Reset()
    _WD_Capabilities_Add($_WD_CAP_GECKO_OPTION_BINARY, 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
    _WD_Capabilities_Add($_WD_CAP_GECKO_OPTION_LOGLEVEL, 'trace')
    _WD_Capabilities_Add($_WD_CAP_GECKO_OPTION_ARGS, '-profile', 'C:\Users\agatk\AppData\Roaming\Mozilla\Firefox\Profiles\5819ktj7.default')

    Local $sDesiredCapabilities = _WD_Capabilities_Create()
    Return SetError(@error, @extended, $sDesiredCapabilities)
EndFunc   ;==>_My_Chrome_Capabilities

 

Edited by mLipok

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

hello sorry again I'm trying to retrieve some data inside a table in the scite log I see that there are but the array does not return me, maybe I am wrong something?

 

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <File.au3>
#include <Array.au3>
#include "wd_core.au3"
#include "wd_helper.au3"
#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>

Global $sDesiredCapabilities, $sSession, $sElement
Global $sGPathProfileBrowser = "C:/Users/Marlon/AppData/Roaming/Mozilla/Firefox/Profiles/fechpd3a.default-release"

SetupGecko(1)
_WD_Startup()
If @error <> $_WD_ERROR_Success Then
    Exit -1
EndIf

$sSession = _WD_CreateSession($sDesiredCapabilities)
_ScrapeEconCalendar()

MsgBox(0, "", "")

_WD_DeleteSession($sSession)
_WD_Shutdown()

Func _ScrapeEconCalendar()
    _WD_Navigate($sSession, "https://www.myfxbook.com/forex-economic-calendar")
    Local $aResult = _WD_GetTable($sSession, "//table[@id='economicCalendarTable']")
    _ArrayDisplay($aResult)

EndFunc   ;==>_ScrapeEconCalendar

Func SetupGecko($iNewOldBrowser)
    If $iNewOldBrowser = 0 Then
        _WD_Option('Driver', 'geckodriver.exe')
        _WD_Option('DriverParams', '--log trace --marionette-port 2828')
        _WD_Option('Port', 4444)
        $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}'
    Else
        _WD_Option('Driver', 'geckodriver.exe')
        _WD_Option('DriverParams', '--log trace --marionette-port 2828')
        _WD_Option('Port', 4444)
        $sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"moz:firefoxOptions": {"args": ["-profile", "' & $sGPathProfileBrowser & '"],"log": {"level": "trace"}}}}}'
    EndIf
EndFunc   ;==>SetupGecko

sorry  

_WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"EUR"}...
_WD_ElementAction: {"value":"EUR"}...
__WD_Get: URL=HTTP://127.0.0.1:4444/session/b88a9748-a67a-42a7-aa7d-686c8b220bb3/element/a3cf1b11-08ba-4ba7-a428-f6e3aed40cb2/text
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Consumer Price Index (EU norm) (MoM)"}...
_WD_ElementAction: {"value":"Consumer Price Index (EU norm) (MoM)"}...
__WD_Get: URL=HTTP://127.0.0.1:4444/session/b88a9748-a67a-42a7-aa7d-686c8b220bb3/element/ef304502-5721-484b-8dcc-2e16bb42c500/text
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"LOW"}...
_WD_ElementAction: {"value":"LOW"}...
"C:\Users\Marlon\Desktop\economic calendart\wd_helper.au3" (1846) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$aTable[$iRow][$iColumn] = _WD_ElementAction($sSession, $aElements[$i], "Text")
^ ERROR

I only entered the final part because everything would have been very long, thanks again 

Edited by Marlon13
Link to comment
Share on other sites

17 minutes ago, Danp2 said:

Something that can be used to build the Desired Capabilities for any supported browser.

_WD_Capabilities_Add() will be able to do so, provided we take all cases into account.
It certainly won't happen right away, but we can start with the simplest and supplement it over time.

Edited by mLipok

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

Link to comment
Share on other sites

Link to comment
Share on other sites

Is there any debuggers that work with the WD Driver? I tried using the Graphical Debugger from here http://www.thefoolonthehill.net/drupal/AutoIt Debugger, but when I try to run it step by step, it just jumps between WinHttps and wd_core in a perpetual loop, after 20 minutes of this I stopped it.

Is there any good tutorials or videos on how to click on buttons, links and banners on the webpage for beginners? Wiki is not too descriptive and does not have syntax or examples. 

 

Link to comment
Share on other sites

hello sorry I have a problem with the browser now in practice after closing the script and disabled marionette every time I try to open the browser is not open and a completely white message box appears with the title firefox and an ok button I press it and it does not start firefox, has this ever happened to you? bye thank you

Link to comment
Share on other sites

I'm using the function _WD_UpdateDriver() to automatically update the chromedriver, it's working very well, but there is one issue: when there is no file the function returns the error $_WD_ERROR_NoMatch. It would be very nice if this function could download the file anyway. For instance, in a new installation of the script, this update could be very helpful. I can do it and send a pull request if you wish.

Link to comment
Share on other sites

Hi @Danp2,

I was wondering if this UDF also supports "Shadow DOM's".
Because i am trying to interact with an element (in this case a Button), but it won't work, also with other elements inside the DOM it doesn't work. Elements outside of the DOM works just fine, so i thought that maybe DOM's are not supported with this UDF?

Using this code;
 

;Find Element
        $aElements = _WD_FindElement($WLF_Session, $_WD_LOCATOR_ByXPath, ".//button[contains(text(),'Filter')]", Default, False, Default)
        
        ;Show Element ID when found
        Msgbox(48,"",$aElements)
        
        ;Click on the Button
        _WD_ElementAction($WLF_Session,$aElements,'click')

In the developer console in Chrome, when i inspect the element, i notice the structure;

<html>
    <body>
        <statup-app>
            #shadow-root (open)
                <style>...</style>
                <div>
                    <button>
                    "Filter "
                    <span id="arrow" class="down"></span>
                    </button>
                </div>
                
                etc,etc,etc

Everything after #shadow-root (open) i cannot interact with, but anything before i can interact with.

 

Thanks :)

Edited by Blueman
Added code
Link to comment
Share on other sites

I have this code in Python, generated by Selenium IDE

 
  def test_enm(self):
    self.driver.get("https://teco3enmui.nh.inet/login/?goto=https://teco3enmui.nh.inet")
    self.driver.set_window_size(864, 708)
    self.driver.find_element(By.ID, "loginNoticeOk").click()
    self.driver.find_element(By.ID, "loginUsername").send_keys("opjcman1")
    self.driver.find_element(By.ID, "loginPassword").send_keys("xxxxx")
    self.driver.find_element(By.ID, "submit").click()
    self.driver.find_element(By.LINK_TEXT, "Alarm Monitor (FM)").click()
    self.vars["window_handles"] = self.driver.window_handles
    self.driver.find_element(By.CSS_SELECTOR, ".ebBtn:nth-child(1) > .elLayouts-ActionBarButton-text").click()

How can I write this 4 lines with Autoit and WebDriver UDF?
    self.vars["win7895"] = self.wait_for_window(2000)
    self.vars["root"] = self.driver.current_window_handle
    self.driver.switch_to.window(self.vars["win7895"])
    self.driver.switch_to.window(self.vars["root"])

   

    self.driver.find_element(By.LINK_TEXT, "opjcman1").click()
    self.driver.find_element(By.CSS_SELECTOR, ".eaUserProfileMenu-link-logout").click()

#And this other 4 lines?

    self.driver.switch_to.window(self.vars["win7895"])
    self.driver.close()
    self.driver.switch_to.window(self.vars["root"])
    self.driver.close()
  
 

Thanks in advance...

Link to comment
Share on other sites

@JMan14 I'm don't have much experience with Python or Selenium, so someone else may jump in here with some better info. To me, it appears that the code gathers some window or tab handles and stores them in local variables. These are then used to switch to that window context.

You would use _WD_Window to retrieve / set the current window. If your last set of code is closing the window / tabs, then you would use _WD_Window for this as well.

Link to comment
Share on other sites

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 07/29/2022
  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...