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 comment
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

Link to comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

  • 4 weeks later...
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...