Jump to content

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
Link to post
Share on other sites
  • Replies 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

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.

Time ago I wrote a function to extract data from  the source HTML code of tables. https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/ Seems that that fun

Hello @GregEisenberg You need to do this: Local $oJsonRect=_WD_ElementAction($sSession, $sElements, 'rect') ConsoleWrite("!" & Json_Get($oJsonRect, "[x]") & @CRLF) ConsoleWr

Posted Images

@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

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

 

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.

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,

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.

 

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

 

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.

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.

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}

 

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.

Link to post
Share on other sites
  • 4 weeks later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By mLipok
      Recently I start wd_capabilities.au3 project on my side.
      I think this is time to share to AutoIt community.
      Check attached UDF: wd_capabilities.au3

      Here is a scratch example showing how to use them:
      #include "wd_helper.au3" #include "wd_capabilities.au3" _Example() Func _Example() ........ ........ ........ _WD_Capabilities_Build_Arguments(Null) ; CLEANUP ARGS _WD_Capabilities_Build_Arguments('--headless') _WD_Capabilities_Build_Arguments('start-maximized') _WD_Capabilities_Build_Arguments('disable-infobars') _WD_Capabilities_Build_Arguments('user-data-dir', 'C:\Users\' & @UserName & '\AppData\Local\Google\Chrome\User Data\Default') Local $s_WD_Capabilities_Arguments = _WD_Capabilities_Build_Arguments(Default) ; GET ARGS _WD_Capabilities_Build_Preferences(Null) ; CLEANUP PREFS If $s_Download_dir Then _WD_Capabilities_Build_Preferences('download.default_directory', $s_Download_dir) Local $s_WD_Capabilities_Preferences = _WD_Capabilities_Build_Preferences(Default) ; GET PREFS Local $s_Desired_Capabilities = _WD_Capabilities_Build_JSON('chrome', $s_WD_Capabilities_Arguments, $s_WD_Capabilities_Preferences) Local $WD_SESSION = _WD_CreateSession($s_Desired_Capabilities) ........ ........ ........ EndFunc  
      I plan to publish the code on GitHub.
      In the indefinite future, when the project becomes more functional, if @Danp2 accepts it, I hope it may be included in the main WebDriver UDF.

      I am waiting for yours feedback and help in the further development of this project.

      REMARK 1:
      As so far this UDF only supports GoogleChrome.
      Adding support for other browsers shouldn't be difficult, I just didn't need to.

      REMARK 2:
      For now, this project is working but still as a early BETA, so please do not discuss, ask questions, or post examples or snippets of code that pertain to any function of this UDF in other part of this forum, until it is found acceptable. Simply: discusion and tests only here in this topic.


      Regards,
      @mLipok
       
    • 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/
      HtmlTable2Array UDF (optional) https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/
      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/ Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      See the wiki for details on the UDF --
      https://www.autoitscript.com/wiki/WebDriver
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/205553-webdriver-udf-help-support-iii/
      Previous support threads (Closed)
      https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/
      https://www.autoitscript.com/forum/topic/201106-webdriver-udf-help-support-ii/
       
    • By Hermes
      I have Index.html where it contains a frame with a source "frame1.html". I can select/highlight elements in index.html but unable to select/highlight elements inside the frame with the src "frame1.html", the autoit output is throwing error:
      __WD_Post: URL=HTTP://127.0.0.1:9515/session/2143396006437be4005db3b84acc1496/element/8be1c3c4-5bb1-42b1-8cde-7954765cbc61/element; $sData={"using":"css selector","value":"frameset:nth-of-type(1)"} __WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\... __WD_Post ==> No match: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"css selector\",\"selector\":\"frameset:nth-of-type(1)\"}\n (Session info: chrome=90.0.4430.212)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00FCE7D3+124883]\n\tOrdinal0 [0x00FCE7B1+124849]\n\tGetHandleVerifier [0x01218688+193832]\n\tGetHandleVerifier [0x0123C478+340760]\n\tGetHandleVerifier [0x012361F1+315537]\n\tGetHandleVerifier [0x012516BA+427354]\n\tGetHandleVerifier [0x01236176+315414]\n\tGetHandleVerifier [0x0125174A+427498]\n\tGetHandleVerifier [0x0125D6EB+476555]\n\tGetHandleVerifier [0x0125154B+426987]\n\tGetHandleVerifier [0x01234FFD+310941]\n\tGetHandleVerifier [0x01235D8E+314414]\n\tGetHandleVerifier [0x01235D19+314297]\n\tGetHandleVerifier [0x012F31EC+1089676]\n\tGetHandleVerifier [0x012F17C9+1082985]\n\tGetHandleVerifier [0x012F13A3+1081923]\n\tGetHandleVerifier [0x013ED9FD+2115741]\n\tOrdinal0 [0x0111B82E+1488942]\n\tOrdinal0 [0x010B5A7D+1071741]\n\tOrdinal0 [0x010B559B+1070491]\n\tOrdinal0 [0x010B54B1+1070257]\n\tOrdinal0 [0x010EFF53+1310547]\n\tBaseThreadInitThunk [0x770662C4+36]\n\tRtlSubscribeWnfStateChangeNotification [0x776B1B69+1081]\n\tRtlSubscribeWnfStateChangeNotification [0x776B1B34+1028]\n"}} Auto IT Script:
      #Include "wd_core.au3" #Include "wd_helper.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, 'index.html') _WD_LoadWait($sSession) Local $index = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)") Local $index1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)", $index) Local $index2 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frame:nth-of-type(1)", $index1) Local $index3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)", $index2) _WD_HighlightElement($sSession, $index2, 1) _WD_HighlightElement($sSession, $index3, 1) _WD_Shutdown() 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, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome  

      frame1.html index.html
    • By Hermes
      Hi, sometimes when I run my script in GUI (SciTe Editor) or as an executable file, the chrome driver launches but the chrome browser does not but when I re-run the script again - chrome driver launches and so does the browser. Here is the error that I'm getting:
      __WD_Post: StatusCode=0; ResponseText=WinHTTP request timed out before Webdriver... __WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver _WD_CreateSession: WinHTTP request timed out before Webdriver _WD_CreateSession ==> Webdriver Exception: HTTP status = 0 Just wondering if there's a way to re-launch both the driver and browser without having to rerun the script/executable.
       
       
    • By SkysLastChance
      I am using web driver and xpaths to automate chrome. 
      I am able to edit everything I need to until I get these pop ups. Then when I try to find the xpath it act like it does not exist. 
      This code below is working to find input fields on the main page of the site. But, if I try the same thing for ones in the popover it will not find it. 😕
      $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[substring(@id, string-length(@id) - string-length('_3') + 1 ) = '_3']") _WD_ElementAction($sSession, $sElement, 'value', "TEST") Here is the html

      Any idea why it is not finding the element inside these pop overs?
       
       
      HTML:
       
×
×
  • Create New...