Jump to content
Danp2

WebDriver UDF - Help & Support

Recommended Posts

@Danp2 Thank you for your prompt answers. $sDesiredCapbilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":["start-maximized"] }}}}' solved my first question. It's good to know that there is no problem in not calling _WD_DeleteSession.

PS: I added "disable-infobars" in the "args" section and it did away with the yellow band at the top which says "chrome is being controlled by automated software."

Edited by CYCho

Share this post


Link to post
Share on other sites

@Danp2

Thank you for your reply. This is my simple code:

<!DOCTYPE html>
<html>
<body>

<h2>The select Element</h2>
<p>The select element defines a drop-down list:</p>

<form action="/action_page.php">
  First name:<br>
  <input type="text" name="firstname"><br>
  Last name:<br>
  <input type="text" name="lastname">
  
  <select name="cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="fiat">Fiat</option>
    <option value="audi">Audi</option>
  </select>
  <br><br>
  <input type="submit">
</form>

</body>
</html>

And i tried to select the Audi  from the drop down menu by this code but failed:

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='cars']")
_WD_ElementAction($sSession, $sElement, 'value', 'audi')

Please help me. 

Thanks

Share this post


Link to post
Share on other sites

Danp2 - this is the Scite - I'm using Firefox and Geckodriver 32-bit

 

+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\PC1\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\PC1\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.3)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\PC1\Documents\AutoIt_code\temp.au3
+>13:44:26 AU3Check ended.rc:0
>Running:(3.3.14.3):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\PC1\Documents\AutoIt_code\temp.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
_WDStartup: OS: WIN_10 WIN32_NT 16299 
_WDStartup: AutoIt: 3.3.14.3
_WDStartup: WD.au3: 0.1.0.3
_WDStartup: Driver: geckodriver
_WDStartup: Params: --binary C:\Program Files (x86)\Mozilla Firefox\firefox.exe
_WDStartup: Port:   2828
__WD_Post: URL=HTTP://127.0.0.1:2828/session; $sData={"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}
"C:\Users\PC1\Documents\AutoIt_code\wd_core.au3" (1068) : ==> The requested action with this object has failed.:
$_WD_OHTTP.Send($sData)
$_WD_OHTTP^ ERROR
->13:44:27 AutoIt3.exe ended.rc:1
+>13:44:27 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 2.533

 

Share this post


Link to post
Share on other sites
On 3/23/2018 at 9:49 AM, giahh said:

And i tried to select the Audi  from the drop down menu by this code but failed:

Why not post a complete snippet of code that we can actually run rather than just these two lines of code?

Also, telling us that it failed doesn't really give the details needed to assist you. Which line failed? Show us the results from the Scite output window.

Share this post


Link to post
Share on other sites

@Danp2

Thank you Danp2,

My issue has been solved. But I got another question. How can I send Page Up, Page Down, or Up Down keys (keyboard press simulator) to my website (for example when im browsing a dropdown select tag and need to press Enter to select an option tag) Post command?

Thanks,

Share this post


Link to post
Share on other sites

@giahh The W3C webdriver protocol supports sending keystrokes to elements. This has been implemented in _WD_ElementAction with the $sCommand parameter set to 'value'.

I haven't researched how to send special characters like you inquired about, so I would recommend that you do your own research and then let us know what you find.

 

Share this post


Link to post
Share on other sites

Well - I've made some headway but I've got to have the Firefox browser open (you can see one of my many failed attempts to direct the program to my firefox.exe (because Firefox isn't my default browser) :

$sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true, {"browserOptions": --binary C:\Program Files (x86)\Mozilla Firefox\firefox.exe, "browserName": firefox, "browserVersion": 59.0.1}}}'

here is my program so far:

#include "wd_helper.au3"
#include "wd_core.au3"
Global $_WD_DRIVER, $aElements
Local $sDesiredCapabilities

SetupGecko()
_WDStartup()
$sSession = _WDCreateSession($sDesiredCapabilities)
_WDNavigate($sSession, 'http://www.bailii.org')

;<input size="45" name="all" type="TEXT">
$sElement = _WDFindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='all']")

If @error = $_WD_ERROR_Success Then
    _WDElementAction($sSession, $sElement, 'value', 'Care B110 2017')
EndIf

;<input name="submit" type="SUBMIT" value="Search">
$sElement = _WDFindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='submit']")
_WDElementAction($sSession, $sElement, 'click')


Func SetupGecko()
    _WDOption('Driver', 'C:\Users\PC1\Documents\AutoIt_code\geckodriver.exe')
    _WDOption('DriverParams', '--log trace')
    _WDOption('Port', 4444)
    $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
    ;$sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true, {"browserOptions": --binary C:\Program Files (x86)\Mozilla Firefox\firefox.exe, "browserName": firefox, "browserVersion": 59.0.1}}}'
EndFunc   ;==>SetupGecko

 

Share this post


Link to post
Share on other sites

I don't believe the default browser matters in this instance. If Firefox is installed in the default location, then it should be found automatically by the webdriver application. Otherwise, you need to provide the executable location so that it can launch the browser.

Are you still getting the error that it can't find the browser? Post the results from the Scite output window.

P.S. Remember that you will need to surround the provided full path with quotes if it contains spaces.

Share this post


Link to post
Share on other sites

You are correct!  I didn't need to give the FF file path once I sorted the correct versions of udfs and geckodriver.exe - I didn't realize that I was running ff 64-bit.  Now to try to download some Word documents from a site.

Share this post


Link to post
Share on other sites

@Danp2

Hello Danp2,

I'm giving up to solve my problem. This is my problem:

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

Local $sDesiredCapabilities

$_WD_DEBUG = True

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

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

$sSession = _WD_CreateSession($sDesiredCapabilities)

; GO TO WEBSITE
_WD_Navigate($sSession, "https://www.lazada.vn/products/man-hinh-vi-tinh-215-inch-samsung-s22f355-den-i100062263-s100083200.html?spm=a2o4n.home.just4u.4.19056afeI3rOAQ&abtest=&pvid=2f299be5-0e7e-4835-bc84-e75bebea5a8b&pos=4&abbucket=&clickTrackInfo=pvid%3A2f299be5-0e7e-4835-bc84-e75bebea5a8b&acm=icms-zebra-5000379-2586240.1003.1.2262806&scm=1007.17519.97321.0&aldid=Lz1dQBZt")

; CHECK PRODUCT AVAILABLE by searching AddtoCart Tag 
Local $addCartTAG = "//button[@class='pdp-button pdp-button_type_text pdp-button_theme_orange pdp-button_size_xl']"
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, $addCartTAG, "", 3000) ;wait 3 seconds for tag to appear

;Add Product to Cart
$addCartButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $addCartTAG)
_WD_ElementAction($sSession, $addCartButton, 'click')

;Shopping Cart
Local $checkoutTAG = "//button[@class='next-btn next-btn-primary next-btn-large checkout-order-total-button automation-checkout-order-total-button-checkout']"
;Verify Cart page by Tag
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, $checkoutTAG, "", 3000) ; wait 3 seconds for tag to appear
;Click Checkout Button
$checkoutButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $checkoutTAG)
_WD_ElementAction($sSession, $checkoutButton, 'click')

;Fill delivery address
;Verify page loaded completely by SAVE BUTTON tag
Local $saveTAG = "//button[@class='next-btn next-btn-primary next-btn-large mod-address-form-btn']"
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, $saveTAG, "", 3000) ; wait 3 seconds for tag to appear

;Because this form didnt assign the name for inputs tag, so I have to search them all
$aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div/input", '', True)

;email input is 7th tag (array result)
_WD_ElementAction($sSession, $aElements[7], 'value', "my-emails@gmail.com")
;name input is 8th tag  (array result)
_WD_ElementAction($sSession, $aElements[8], 'value', "Full Name")
;fone input is 9th tag  (array result)
_WD_ElementAction($sSession, $aElements[9], 'value', "01234567890")
;address input is 11th tag  (array result)
_WD_ElementAction($sSession, $aElements[11], 'value', "This is my address")

;This field is City
; I got trouble by this because they didnt use SELECT tag instead. 
 My solution is try to click on it then need to press DOWN key 1 or 2 times and finally press Enter key on the keyboard to select "An Giang" value. But all failed to try all kind of way to Send key via keyboard, do dou have any idea to help me this? Or any betterway to select that Value without using ;interact with keyboard?
$aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//i[@class='next-icon next-icon-arrow-down next-icon-medium next-select-arrow']", '', True)
_WD_ElementAction($sSession, $aElements[0], 'click')

Sleep(100000)
MsgBox("", "", "")

_WD_DeleteSession($sSession)
_WD_Shutdown()

Thank you so much for your helping.

Share this post


Link to post
Share on other sites

To continue trying to emulate key pressing. I use actions method by reading here by Enter some enter via keyboard to an Input field,

by add this case to our function by using the example given by them. (press and hold shift then press s and release shift)

Case 'actions'
            Local $sSplitValue = $sOption
            $sResponse = __WD_Post($_WD_BASE_URL & ":" & $_WD_PORT & "/session/" & $sSession & "/" & $sCommand, ' {"actions": [{"type": "key","id": "keyboard","actions": [{"type": "keyDown", "value": "\uE009"},{"type": "keyDown", "value": "s"},{"type": "keyUp", "value": "\uE009"},{"type": "keyUp", "value": "s"}]}]}')
            $iErr = @error

            If $iErr = $_WD_ERROR_Success Then
                $sResult = $sResponse
            EndIf

but they always get error.

__WD_Post: URL=HTTP://127.0.0.1:9515/session/48ec722716f4209fdf7785890d823d93/actions; $sData= {"actions": [{"type": "key","id": "keyboard","actions": [{"type": "keyDown", "value": "\uE009"},{"type": "keyDown", "value": "s"},{"type": "keyUp", "value": "\uE009"},{"type": "keyUp", "value": "s"}]}]}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"unknown command","message":"(Session infochrome=65.0.3325.181)","stacktrace":"Backtrace:\n\t(No symbol) [0x0145D110]\n\t(No symbol) [0x014466BD]\n\t(No symbol) [0x01416131]\n\t(No symbol) [0x013FBF50]\n\t(No symbol) [0x013F6927]\n\t(No symbol) [0x013E0C6E]\n\t(No symbol) [0x013E2174]\n\t(No symbol) [0x013E211A]\n\t(No symbol) [0x0148254F]\n\t(No symbol) [0x014610F3]\n\t(No symbol) [0x0142F786]\n\t(No symbol) [0x0142FAC3]\n\t(No symbol) [0x0142FBD3]\n\t(No symbol) [0x014631F7]\n\t(No symbol) [0x0142F4CF]\n\t(No symbol) [0x0143074E]\n\t(No symbol) [0x0142C16B]\n\t(No symbol) [0x0142C2C5]\n\t(No symbol) [0x0143EAFB]\n\tBaseThreadInitThunk [0x76A87C04+36]\n\tRtlInitializeExceptionChain [0x776BB90F+143]\n\tRtlInitializeExceptionChain [0x776BB8DA+90]\n"}}
_WD_ElementAction: {"value":{"error":"unknown command","message":"(Session infochrome=65.0.3325.181)","stacktrace":"Backtrace:\n\t(No symbol) [0x0145D110]\n\t(No symbol) [0x014466BD]\n\t(No symbol) [0x01416131]\n\t(No symbol) [0x013FBF50]\n\t(No symbol) [0x013F6927]\n\t(No symbol) [0x013E0C6E]\n\t(No symbol) [0x013E2174]\n\t(No symbol) [0x013E211A]\n\t(No symbol) [0x0148254F]\n\t(No symbol) [0x014610F3]\n\t(No symbol) [0x0142F786]\n\t(No symbol) [0x0142FAC3]\n\t(No symbol) [0x0142FBD3]\n\t(No symbol) [0x014631F7]\n\t(No symbol) [0x0142F4CF]\n\t(No symbol) [0x0143074E]\n\t(No symbol) [0x0142C16B]\n\t(No symbol) [0x0142C2C5]\n\t(No symbol) [0x0143EAFB]\n\tBaseThreadInitThunk [0x76A87C04+36]\n\tRtlInitializeExceptionChain [0x776BB90F+143]\n\tRtlInitializeExceptionChain [0x776BB8DA+90]\n"}}
__WD_Delete: URL=HTTP://127.0.0.1:9515/session/48ec722716f4209fdf7785890d823d93
__WD_Delete: StatusCode=200; ResponseText={"value":null}
_WD_DeleteSession: {"value":null}

 

Share this post


Link to post
Share on other sites

@giahh A few items to ponder --

1) I don't think that coding change is necessary because the feature you are looking for belongs to and is already available in _WD_Action.

2) According to this link, the Actions implementation in the Chrome webdriver is incomplete. More details here.

Feel free to elaborate if you believe I have misunderstood your intentions.

Share this post


Link to post
Share on other sites

@Danp2 : I have a problem about waiting to page complete loading. Do it have a function or a ways to timeout page loading. Example : If the page loading > 30s, turn off browser ? Thanks you very much.

Share this post


Link to post
Share on other sites

 

The answer to "disable-infobars" ChromeOption is this:

'{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args": ["--disable-infobars"]}}}}'

 

Edited by Decibel

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Similar Content

    • By Danp2
      Introduction
      This UDF will allow you to interact with any browser that supports the W3C WebDriver specifications. Supporting multiple browsers via the same code base is now possible with just a few configuration settings.
      Requirements
      JSON UDF https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn
      WinHTTP UDF https://www.autoitscript.com/forum/topic/84133-winhttp-functions/
      WebDriver for desired browser
      Chrome WebDriver https://sites.google.com/a/chromium.org/chromedriver/downloads FireFox WebDriver https://github.com/mozilla/geckodriver/releases Edge WebDriver https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Function List
      Core Functions
      _WD_CreateSession($sDesiredCapabilities='{}') _WD_DeleteSession($sSession) _WD_Status() _WD_Timeouts($sSession, $sTimeouts = '') _WD_Navigate($sSession, $sURL) _WD_Action($sSession, $sCommand) _WD_Window($sSession, $sCommand, $sOption = '') _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement = "", $lMultiple = False) _WD_ElementAction($sSession, $sElement, $sCommand, $sOption='') _WD_ExecuteScript($sSession, $sScript, $sArguments="[]") _WD_Alert($sSession, $sCommand, $sOption = '') _WD_GetSource($sSession) _WD_Cookies($sSession, $sCommand, $sOption = '') _WD_Option($sOption, $vValue = "") _WD_Startup() _WD_Shutdown() Helper Functions
      _WD_NewTab($sSession, $lSwitch = True, $iTimeout = -1, $sURL = "", $sFeatures = "") _WD_Attach($sSession, $sString, $sMode = 'title') _WD_LinkClickByText($sSession, $sText, $lPartial = True) _WD_WaitElement($sSession, $sElement, $sStrategy, $sSelector[, $iDelay = 0[, $iTimeout = -1]]) _WD_GetMouseElement($sSession) _WD_GetElementFromPoint($sSession, $iX, $iY) _WD_LastHTTPResult() _WD_GetFrameCount() _WD_IsWindowTop() _WD_FrameEnter($sIndexOrID) _WD_FrameLeave() _WD_HighlightElement($sSession, $sElement[, $iMethod = 1]) _WD_HighlightElements($sSession, $aElements[, $iMethod = 1]) _WD_jQuerify($sSession) WD_ElementOptionSelect($sSession, $sStrategy, $sSelector, $sStartElement = "") _WD_ConsoleVisible($lVisible = False) _WD_Screenshot($sSession, $sElement = '', $nOutputType = 1) Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/
    • 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 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
×
×
  • Create New...