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.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • 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/ 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/201106-webdriver-udf-help-support-ii/
    • By Langmeister
      I am once again asking for your experienced assistance. If I open a website that uses notifications I am asked to allow or block them for that website after a few seconds. This notification pops up every time the page gets navigated to, even tho you have clicked on allow for several times. I am explicitly not searching for smth to get rid of "Chrome is being controlled by automated test sw". Instead I am searching for a line of script to disable all notifications by default: like here chrome://settings/content/notifications. 
      This is code should give you an example of what notifications I am talking about:
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://webradio.planetradio.de/") _WD_LoadWait($sSession)  
    • By Langmeister
      Hi, I'm sure that this is a simple question regarding webdriver udf but my search on the forum did not result in the exact same scenario that I need. I will adapt it to my corporate needs but at first I want it to work with an example everybody can reproduce if needed.
      I navigate to https://www.daysoftheyear.com/ and want to find out what special day today is. Using the following Code returns the wanted text that today is 'shark awareness day' in the console but it is not pasted in notepad as it is not copied as it probably should be.
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan") _WD_LoadWait($sSession) Sleep(3000) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a") _WD_ElementAction($sSession, $sElement, 'text') ClipGet() Run("notepad.exe") Sleep(500) Send("^v") Scite returns this, therefore the text has been found but the last mile to paste it to notepad or excel does not work for me.
      __WD_Get: URL=HTTP://127.0.0.1:9515/session/b72166b774d7fefb258b3721fc1d4306/element/657e6b5d-31a9-46a8-85c4-acb7f72bf659/text __WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Shark Awareness Day"}... _WD_ElementAction: {"value":"Shark Awareness Day"}... Thanks in advance! 
       
    • By Langmeister
      Hi, I need help performing actions in Salesforce using IE. I used to complete tasks via MouseMove/MouseClick etc. on the Chrome application of SF, but unfortunately this only works for me and not my colleagues due to different positions of things etc. Being unable to get Webdriver UDF or Chromedriver running to interact with the code directly, I chose to look into the IE UDF. ATM I'm trying to tick a specific checkbox in SF which simply allows me to "select all checkboxes" at the same time. Applying the following code on a random website with checkboxes works just fine for me: (in this case selecting cheese checkbox)
      #include <IE.au3> Local $oIE = _IECreate("http://www.echoecho.com/htmlforms09.htm") Local $oSubmit = _IEGetObjByName($oIE, "option3") _IEAction($oSubmit, "click") _IELoadWait($oIE) But applying it to the Salesforce website it does exactly nothing and responds with these warnings/errors:
      The script is exactly the same, except for website and the input name tag of the desired checkbox being different.
      #include <IE.au3> Local $oIE = _IECreate("Corporate Salesforce URL") Local $oSubmit = _IEGetObjByName($oIE, "myPage:myForm:oliListBlock:oliListTable:j_id36") _IEAction($oSubmit, "click") _IELoadWait($oIE) As its working with random websites my guess is that there has to be something done to get it work with SF.
      Hope the more experienced SF+AutoIt pros can help me out here. Thanks in advance!
    • By JohnWIlling
      We are running on a VIrtual Machine via Remote Desktop.  We are having a situation where the loading of the chromedriver.exe is taking longer on the VM than on a physical machine.  It is causing the first call to  WD_Post in _WD_CreateSession to fail.
      To workaround the Issue, I used a simplified version of (_WinAPI_GetTcpTable) UDF to Loop waiting for the driver port to be in the listening state.  At that point, I know that the Post will work:
      Func _WaitForPort($ListenPort) Do Local $tMIB_TCPTABLE = DllStructCreate("dword[6]") Local $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", 0, "BOOL", True) Local $dwSize = $aRet[2] $tMIB_TCPTABLE = DllStructCreate("DWORD[" & $dwSize / 4 & "]") $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", $dwSize, "BOOL", True) If $aRet[0] <> 0 Then Return SetError(1) Local $iNumEntries = DllStructGetData($tMIB_TCPTABLE, 1, 1) Local $aRes[$iNumEntries][6] For $i = 0 To $iNumEntries - 1 Local $Type = DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 0) $aRet = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 2)) ; local port Local $Port = $aRet[0] ConsoleWrite("Checking Row:" & $i & " State:<" & $Type & "> Port:<" & $Port & ">" & @CRLF) ; Type 2 is LISTENING If $Type = 2 And $Port = $ListenPort Then Return 1; EndIF Next Sleep(500); Until 0; Return 0; EndFunc ;==>_WaitForPort  
×
×
  • Create New...