Jump to content
Danp2

WebDriver UDF (W3C compliant version) - 09/17/2018

Recommended Posts

Danp2

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, _
            $eChrome

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
        SetupGecko()

    Case $eChrome
        SetupChrome()

EndSwitch

_WDStartup()

$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)
        Call($aTestSuite[$iIndex][0])
    Else
        ConsoleWrite("Bypass: " & $aTestSuite[$iIndex][0] & @CRLF)
    EndIf
Next

_WDDeleteSession($sSession)
_WDShutdown()



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

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)
EndFunc

;_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']")
    EndIf

    $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)
EndFunc

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

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


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

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

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

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

 

Share this post


Link to post
Share on other sites
Danp2

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
NguyenLe

It not working

Can you help me?

 

 

Untitled.png

Share this post


Link to post
Share on other sites
Danp2

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. 

Share this post


Link to post
Share on other sites
NguyenLe

 

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
NguyenLe

My complete results:

_WDStartup: OS: WIN_7 WIN32_NT 7601 Service Pack 1
_WDStartup: AutoIt: 3.3.14.2
_WDStartup: WD.au3: 0.1.0.1b-1
_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://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}

 

Share this post


Link to post
Share on other sites
Danp2

Ok... so you're running Autoit 3.3.14.2. :thumbsup:  Now, how about Chrome? What version and is it installed in the default location?

Also, what happens at this point in the script? Is the script still running (it appears to be)? Does it just hang or pause? For how long?

Share this post


Link to post
Share on other sites
NguyenLe

The version of Chrome which I am using is 63.0.3239.132

Nothing happens while running the code and the script is running

Share this post


Link to post
Share on other sites
Danp2
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
NguyenLe

The default location of Chrome: C:\Program Files (x86)\Google\Chrome\Application

The version of Chrome:  63.0.3239.132

Share this post


Link to post
Share on other sites
Danp2

@NguyenLe Please let me know if you did the follow as previously requested.

8 hours ago, Danp2 said:

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
NguyenLe

Thank you Danp2.

I'm glad I was able to use it normally after rebooting.

Thanks for your answers

Share this post


Link to post
Share on other sites
NguyenLe

How do I open multi Tab in Chrome?

Thank you very much

Share this post


Link to post
Share on other sites
NguyenLe

Ok, Thank you very much about your UDF.

Share this post


Link to post
Share on other sites
Danp2

Looks like you can do it with the Execute Script feature --

_WDExecuteScript($sSession, 'window.open()', '{}')

Once the tab is created, you will need to switch to it using the correct commands before you can interact with it.

Share this post


Link to post
Share on other sites
Danp2

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] & '"}')
    EndIf
EndFunc

 

Share this post


Link to post
Share on other sites
NguyenLe

Ok thank you

Can you add to your UDF for everyone to use?

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

    • Danp2
      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.
    • daluu
      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.
      https://github.com/daluu/AutoItDriverServer
      with specific demo examples here:
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/CalculatorTest.java
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/calculator.py
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationTest.java
      https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/SeleniumIntegrationWithAutoItDriver.py
    • TechCoder
      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.    
      Marquee_W3C.au3
      MarqueeMaker.au3
×