Jump to content

WebDriver UDF (W3C compliant version) - 9/10/2019

Recommended Posts

Here's some code for testing the UDF functions. Note how you can switch between browsers by altering just a few settings --

#include "webdriver.au3"

Local Enum $eFireFox = 0, _

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

Local Const $_TestType = $eChrome
Local $sDesiredCapabilities
Local $iIndex

$_WD_DEBUG = True

Switch $_TestType
    Case $eFireFox

    Case $eChrome



$sSession = _WDCreateSession($sDesiredCapabilities)
$sStatus = _WDStatus()

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


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

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

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

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

    If @error = $_WD_ERROR_NoMatch Then
        $sElement = _WDFindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib']")

    $sElement2 = _WDFindElement($sSession, $_WD_LOCATOR_ByXPath, "//div/input", '', True)

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

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

    $sElement = _WDFindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib']")
    $sValue = _WDElementAction($sSession, $sElement, 'property', 'value')

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

Func TestScript()
    _WDExecuteScript($sSession, 'alert()', "")
    _WDAlert($sSession, 'Dismiss')

Func TestCookies()
    _WDNavigate($sSession, "http://google.com")
    _WDCookies($sSession, 'Get', 'NID')

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

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

Func SetupChrome()
_WDOption('Driver', 'chromedriver.exe')
_WDOption('Port', 9515)
_WDOption('DriverParams', '--log-path=' & @ScriptDir & '\chrome.log')

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


Share this post

Link to post
Share on other sites

I'm sure there are some bugs. Please post any issues you encounter. Also would appreciate any feedback / suggestions.

Note: not all WebDriver functions have been implemented by each browser. To check the status, click on the below link for each respective browser --

- Firefox

- Chrome

Share this post

Link to post
Share on other sites


13 minutes ago, Danp2 said:

You'll need to be more specific because I don't know how to fix "not working". ;) Is it just not launching Chrome or what?

What version of Autoit are you using? Ditto for Chrome. 

I am using Atuoti v3

Share this post

Link to post
Share on other sites

My complete results:

_WDStartup: OS: WIN_7 WIN32_NT 7601 Service Pack 1
_WDStartup: AutoIt:
_WDStartup: WD.au3:
_WDStartup: Driver: chromedriver.exe
_WDStartup: Params: --log-path=D:\New folder\New folder\auto4 V1.651\chrome.log
_WDStartup: Port:   9515
__WD_Post: URL=HTTP://; $sData={"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}


Share this post

Link to post
Share on other sites
11 minutes ago, Danp2 said:

Now, how about Chrome? What version and is it installed in the default location?

@NguyenLe Please answer the bolded portion of my earlier question. If Chome isn't installed in the default location, then ChromeDriver can't locate it in order to launch it. This can be addressed, but you then have to indicate this location to the ChromeDriver.

Also, check the chrome.log file located in the script directory to see if it gives any additional information that may help with this issue.

Share this post

Link to post
Share on other sites

Here's a helper function for creating a new tab and optionally switching to it --

Func _WD_NewTab($sSession, $lSwitch = True)
    _WDExecuteScript($sSession, 'window.open()', '{}')

    Local $aHandles = _WDWindow($sSession, 'handles', '')

    If $lSwitch Then
        _WDWindow($sSession, 'Switch', '{"handle":"' & $aHandles[UBound($aHandles) - 1] & '"}')


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Davidowicza
      Hey guys,
      I am creating my very first script that automates a browser (I usually work with program installs and database automation) and have come across an issue that I am totally stumped on. I need to click an element that gives me a drop down list box but the Xpath to the element changes with every instance of chrome I start...
      I have tried selecting the class, rect, and path but no luck. It never finds the element. (I could be doing this wrong since I am not good at HTML)
      Element I need to select:
      This is the Xpath for the last 3 instances of chrome I have run the script with:
      //*[@id="highcharts-5bp9crq-8"]/svg/g[6]/g/rect //*[@id="highcharts-fiw9szv-8"]/svg/g[6]/g/rect //*[@id="highcharts-5szkmx8-8"]/svg/g[6]/g/rect As you can see the path changes every time.
      How I am trying to select the element:
      ;Check for box element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") MsgBox(0, "", "check for timeout") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='highcharts-5bp9crq-8']/svg/g[6]/g") _WD_ElementAction($sSession, $sElement, 'click') Maybe someone has come across this before and found a work around without using mouseclick()
      Thanks guys, hopefully I am just very overlooking something simple and can be pointed to the right solution.
      Side Note: I wish I could share the webpage entirety, but it has sensitive information with my agency that I cannot share. If you need more, just let me know and I will try and post as much as I can.
    • By Danp2
      This is the "General Help and Support" thread for the WebDriver UDF.
      The UDF itself can be downloaded here.
      So if you have any questions, suggestions or errors please post here.
    • By daluu
      This is kind of already posted here:
      '?do=embed' frameborder='0' data-embedContent>>
      but wanted to note this in this forum of example scripts in case some people only look in this forum for examples and not the other forums with respect to AutoIt integration or relation to Selenium WebDriver.
      So, the example in summary is: you can use Selenium WebDriver API to do AutoIt GUI automation (the ControlXyz() and WinXyz() functons, along with mouse and "send keys" functions). Although I suppose that might be opposite or counter to what most examples here are about - using AutoIt to do or control other stuff rather than using other stuff to control/run AutoIt. But regardless, it is an example implementation of a different use case for AutoIt beyond the general AutoIt community, like those who also use Selenium WebDriver and/or need to integrate Selenium with AutoIt for remote deployment.
      with specific demo examples here:
    • By TechCoder
      Below you will find both a new Marquee UDF (many W3C/HTML5 features and more) as well as a user-friendly program that both serves as an example script, as well as it will create the code for any particular marquee for you!  Enjoy!   ~~~~~~~~~~~~~~~~~  BACKGROUND on <marquee> ~~~~~~~~~~~~~~~~~ <marquee> has been classed as "non-standard" and "non-conforming" as an HTML element   (http://www.w3.org/wiki/HTML/Elements/marquee)  There is no promise that it will continue to be supported in the future, though it is obvious that many people have a need for this feature and it has remained in the major browsers for years.....   <marquee> was originally built into Internet Explorer only, now supported in other browsers, though some original features do not work in IE either - it is clearly trying to be phased out, though a 'replacement' of sorts is coming around, using HTML5 components, so I think it will never totally go away. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   For a project I'm working on, I need a way to create a LOT of different marquees.  I thought it simpler to have a program create the code needed, and built the attached 'user interface' program using various references to the feature.   THE USER PROGRAM IS BACKWARD COMPATIBLE WITH THE EXISTING UDF FROM Melba23   I also needed some features that are not part of the UDF from Melba23 that are direct references to current (HTML5) recommendations from http://www.w3.org/TR/CSS2/, so I modified the current UDF to create the additional functions, which make the UDF more HTML5 compliant (some of the features I built in have no HTML5 component, existing functions were updated only where needed for the first release - perhaps someday the rest can be done, though no immediate plans)    *******************************************************************************************************************************    KNOWN ISSUES and/or LIMITATIONS within the user program   - Tip text NOT IMPLEMENTED (from _GUICtrlMarquee_SetDisplay $sTipTxt) - I had no use for it in my project, though it is not difficult to add if you need to   - border styles do not correspond to w3.org settings (not the program's fault...) This article (http://webdesign.about.com/od/beginningcss/a/aa091207.htm) states that IE does not support 'groove', 'ridge', 'inset' or 'outset' styles, yet does support 'dotted', 'dashed' and 'double'.   Testing has proven this is true for IE (11), however, in testing AutoIt (with the Marquee UDF), which I thought uses IE (?), it appears that just the OPPOSITE of this is true.  Another item for further testing/study.........   - 'Align' feature not working 100% on all fonts (not the program's fault! the initial version of <marquee> (designed for IE and copied to other browsers later) contained an element called 'align', which has long been obsolete in favor of css 'vertical-align', however, it is not a direct replacement  and does not work inside <marquee>.     Several alternatives were tried (including 'line-height' and even 'vspace', which may also soon be phased out) and nothing works 'perfectly' (search the web on font sizing and spacing - you will see this is extremely difficult).        This program works around these challenges in a 'best effort' way, using calculations and 'top-margin' (or vspace) spacing.        'Recommended' fonts (http://www.autoitscript.com/autoit3/docs/appendix/fonts.htm) will be set to 'center' or 'bottom' (within a pixel or 2), while other fonts may be off by several pixels (something in the font is different..).        If you need the other fonts, a bit of testing would give some offset numbers that could result in better display. (this is NOT on my list to do, though maybe someone would want to take that on???)   - You can create 'unreadable', 'unusable' and even 'UGLY' marquees (not the program's fault, either!) While a bit of effort was put into limiting things, there is no cross-checking to make sure your marquee will look 'nice'.  All parameters within the marquee feature have been tested to their max/min limits (and pushed well past the documented limits for speed and delay - you can make a  F A S T  or  S L O W  marquee well outside the published specs!) and set accordingly.   Any/all color scheme, font size, etc. can be used (no matter how horrible the outcome...) so have fun and create what you like!    *******************************************************************************************************************************   Additional recommendations from w3.org built into Marquee_W3C.au3 UDF   1. Border thickness (width) refered as "thin", "medium" and "thick" or <length> (any number - to infinity)      (http://www.w3.org/TR/CSS2/box.html#border-properties)     (http://www.w3schools.com/jsref/prop_style_borderwidth.asp) Marquee_W3C UDF allows any number as an entry, as well as the more 'friendly' named terms   2. Border Style is included in Marquee_W3C UDF (not in the current UDF, therefore, none of the settings in the user program do anything if you use the old UDF, so it is set to $GUI_DISABLE.)   3. use of PIXELS and EM for formatting text instead of POINTS      http://www.w3.org/TR/CSS2/fonts.html#font-size-props use <length> paramaters      http://www.w3.org/TR/CSS2/syndata.html#value-def-length with named length units (em, ex, cm, in, px, etc.)   POINTS are used in typsetting, while PIXELS, and EM are more correct methods of sizing fonts on modern monitors (one good article on this topic can be found at http://webdesign.about.com/cs/typemeasurements/a/aa042803a.htm )   NOTE: The user program is backward compatible with the UDF from Melba23 that uses POINTS and auto-sets the parameter with the chosen UDF.    
  • Create New...