Jump to content

WebDriver UDF - Help & Support


Recommended Posts

Hi Dan !

I downloaded  the latest version of the webriver and i found this function : 

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_ElementOptionSelect
; Description ...: Find and click on an option from a Select element
; Syntax ........: _WD_ElementOptionSelect($sSession, $sStrategy, $sSelector[, $sStartElement = ""])
; Parameters ....: $sSession            - Session ID from _WDCreateSession
;                  $sStrategy           - Locator strategy. See defined constant $_WD_LOCATOR_* for allowed values
;                  $sSelector           - Value to find
;                  $sStartElement       - [optional] Element ID of element to use as starting point
; Return values .: None
;                  @ERROR       - $_WD_ERROR_Success
;                                  - $_WD_ERROR_NoMatch
;                  @EXTENDED    - WinHTTP status code
; Author ........: Dan Pollak
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WD_ElementOptionSelect($sSession, $sStrategy, $sSelector, $sStartElement = "")


    Local $sElement = _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement)

    If @error = $_WD_ERROR_Success Then
        _WD_ElementAction($sSession, $sElement, 'click')
    EndIf
EndFunc


In this website : https://www.nvidia.fr/Download/index.aspx?lang=fr

We ve got a lot of select box  and all i want is to select a specifical value  on the selectbox
I but i still can t understand how i can select a value using this function

Can you give us an example using the demo script and the url I gave ?

Thanks for all

Link to comment
Share on other sites

Hi Dan ! 

Hi tried your exemple and it does not works 

Here is the stack trace : 

_WDStartup: OS:    WIN_7 WIN32_NT 7601 Service Pack 1
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.1.0.18
_WDStartup: Driver:    chromedriver.exe
_WDStartup: Params:    --log-path="D:\Users\u05e265\Desktop\AUTOIT WebDriver\chrome.log"
_WDStartup: Port:    9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}
__WD_Post: StatusCode=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"acceptSslCerts":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5)","userDataDir":"D:\\Users\\u05e265\\AppData\\Local\\Temp\\scoped_dir5632_20627"},"cssSelectorsEnabled":true,"databaseEnabled":false,"goog:chromeOptions":{"debuggerAddress":"localhost:63634"},"handlesAlerts":true,"hasTouchScreen":false,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platform":"Windows NT","rotatable":false,"setWindowRect":true,"takesHeapSnapshot":true,"takesScreenshot":true,"unexpectedAlertBehaviour":"","version":"72.0.3626.121","webStorageEnabled":true},"sessionId":"5766ba7923d0d61aabe32d4a5509499f"}}
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"acceptSslCerts":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5)","userDataDir":"D:\\Users\\u05e265\\AppData\\Local\\Temp\\scoped_dir5632_20627"},"cssSelectorsEnabled":true,"databaseEnabled":false,"goog:chromeOptions":{"debuggerAddress":"localhost:63634"},"handlesAlerts":true,"hasTouchScreen":false,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platform":"Windows NT","rotatable":false,"setWindowRect":true,"takesHeapSnapshot":true,"takesScreenshot":true,"unexpectedAlertBehaviour":"","version":"72.0.3626.121","webStorageEnabled":true},"sessionId":"5766ba7923d0d61aabe32d4a5509499f"}}
Bypass: DemoTimeouts
Running: DemoNavigation
__WD_Post: URL=HTTP://127.0.0.1:9515/session/5766ba7923d0d61aabe32d4a5509499f/window/maximize; $sData=
__WD_Post: StatusCode=200; ResponseText={"value":{"height":1026,"width":1696,"x":-8,"y":-8}}
_WD_Window: {"value":{"height":1026,"width":1696,"x":-8,"y":-8}}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/5766ba7923d0d61aabe32d4a5509499f/url; $sData={"url":"https://www.nvidia.fr/Download/index.aspx?lang=fr"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/5766ba7923d0d61aabe32d4a5509499f/element; $sData={"using":"xpath","value":"//select[@id='selProductSeriesType']/option[5]?"}
__WD_Post: StatusCode=400; ResponseText={"value":{"error":"invalid selector","message":"Unable to locate an element with the xpath expression //select[@id='selProductSeriesType']/option[5]? because of the following errorSyntaxErrorFailed to execute 'evaluate' on 'Document'The string '//select[@id='selProductSeriesType']/option[5]?' is not a valid XPath expression.(Session infochrome=72.0.3626.121)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0136AA90+830096]\n\tOrdinal0 [0x0131581D+481309]\n\tOrdinal0 [0x012EAC47+306247]\n\tOrdinal0 [0x012EC81C+313372]\n\tOrdinal0 [0x012EC706+313094]\n\tOrdinal0 [0x012B8431+99377]\n\tOrdinal0 [0x012D3440+209984]\n\tOrdinal0 [0x012CAAD0+174800]\n\tOrdinal0 [0x012D208B+204939]\n\tOrdinal0 [0x012CA93B+174395]\n\tOrdinal0 [0x012B2D54+77140]\n\tOrdinal0 [0x012B430C+82700]\n\tOrdinal0 [0x012B4260+82528]\n\tOrdinal0 [0x01375302+873218]\n\tOrdinal0 [0x01320553+525651]\n\tOrdinal0 [0x01320783+526211]\n\tOrdinal0 [0x0132086C+526444]\n\tOrdinal0 [0x013783A7+885671]\n\tOrdinal0 [0x013203BF+525247]\n\tOrdinal0 [0x0132A60E+566798]\n\tOrdinal0 [0x01335DDB+613851]\n\tOrdinal0 [0x01335F45+614213]\n\tOrdinal0 [0x01335175+610677]\n\tBaseThreadInitThunk [0x75FA344D+18]\n\tRtlInitializeExceptionChain [0x775E9802+99]\n\tRtlInitializeExceptionChain [0x775E97D5+54]\n"}}
_WD_FindElement: {"value":{"error":"invalid selector","message":"Unable to locate an element with the xpath expression //select[@id='selProductSeriesType']/option[5]? because of the following errorSyntaxErrorFailed to execute 'evaluate' on 'Document'The string '//select[@id='selProductSeriesType']/option[5]?' is not a valid XPath expression.(Session infochrome=72.0.3626.121)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0136AA90+830096]\n\tOrdinal0 [0x0131581D+481309]\n\tOrdinal0 [0x012EAC47+306247]\n\tOrdinal0 [0x012EC81C+313372]\n\tOrdinal0 [0x012EC706+313094]\n\tOrdinal0 [0x012B8431+99377]\n\tOrdinal0 [0x012D3440+209984]\n\tOrdinal0 [0x012CAAD0+174800]\n\tOrdinal0 [0x012D208B+204939]\n\tOrdinal0 [0x012CA93B+174395]\n\tOrdinal0 [0x012B2D54+77140]\n\tOrdinal0 [0x012B430C+82700]\n\tOrdinal0 [0x012B4260+82528]\n\tOrdinal0 [0x01375302+873218]\n\tOrdinal0 [0x01320553+525651]\n\tOrdinal0 [0x01320783+526211]\n\tOrdinal0 [0x0132086C+526444]\n\tOrdinal0 [0x013783A7+885671]\n\tOrdinal0 [0x013203BF+525247]\n\tOrdinal0 [0x0132A60E+566798]\n\tOrdinal0 [0x01335DDB+613851]\n\tOrdinal0 [0x01335F45+614213]\n\tOrdinal0 [0x01335175+610677]\n\tBaseThreadInitThunk [0x75FA344D+18]\n\tRtlInitializeExceptionChain [0x775E9802+99]\n\tRtlInitializeExceptionChain [0x775E97D5+54]\n"}}
_WD_FindElement ==> Webdriver Exception: HTTP status = 400
Bypass: DemoElements
Bypass: DemoScript
Bypass: DemoCookies
Bypass: DemoAlerts
Bypass: DemoFrames
Bypass: DemoActions
Bypass: DemoWindows

To try you can place this code on the wd_demo.au3 

Func DemoNavigation()
;~     _WD_Navigate($sSession, "http://google.com")
;~     _WD_NewTab($sSession)
;~     _WD_Navigate($sSession, "http://yahoo.com")
;~     _WD_NewTab($sSession, True, -1, 'http://bing.com', 'width=200,height=200')

;~     ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
;~     _WD_Attach($sSession, "google.com", "URL")
;~     ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
;~     _WD_Attach($sSession, "yahoo.com", "URL")
;~     ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)

    _WD_Window($sSession, "maximize")
    _WD_Navigate($sSession, "https://www.nvidia.fr/Download/index.aspx?lang=fr")
    _WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@id='selProductSeriesType']/option[5]")

EndFunc

Thanks for your help

Link to comment
Share on other sites

1 hour ago, Danp2 said:

Yes, just run the same Javascipt command using _WD_ExecuteScript.

_WD_ExecuteScript($sSession, "$(#CurrencyCalc).removeClass('hidden');")
Quote

__WD_Post: URL=HTTP://127.0.0.1:9515/session/de34cbaef11af78e403d4cc64e5b4349/execute/sync; $sData={"script":"$(#CurrencyCalc).removeClass('hidden');", "args":[[]]}
__WD_Post: StatusCode=500; ResponseText={"value":{"error":"unknown error","message":"Runtime.evaluate threw exception: SyntaxError: Unexpected identifier\n  (Session info: chrome=74.0.3729.131)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00E6DB63+1432419]\n\tOrdinal0 [0x00DE8D81+888193]\n\tOrdinal0 [0x00D8B9D1+506321]\n\tOrdinal0 [0x00D90907+526599]\n\tOrdinal0 [0x00D8D34D+512845]\n\tOrdinal0 [0x00D8D184+512388]\n\tOrdinal0 [0x00D8D562+513378]\n\tOrdinal0 [0x00D47366+226150]\n\tOrdinal0 [0x00D3EA0D+190989]\n\tOrdinal0 [0x00D46D94+224660]\n\tOrdinal0 [0x00D3E8AB+190635]\n\tOrdinal0 [0x00D25F16+89878]\n\tOrdinal0 [0x00D2757A+95610]\n\tOrdinal0 [0x00D27474+95348]\n\tGetHandleVerifier [0x00FCDE7C+1274156]\n\tGetHandleVerifier [0x00F1B6D9+543113]\n\tGetHandleVerifier [0x00F1B4E0+542608]\n\tOrdinal0 [0x00E7B508+1488136]\n\tGetHandleVerifier [0x00F1BC86+544566]\n\tOrdinal0 [0x00DFEEC5+978629]\n\tOrdinal0 [0x00E0B35B+1028955]\n\tOrdinal0 [0x00E0B49F+1029279]\n\tOrdinal0 [0x00E0A445+1025093]\n\tBaseThreadInitThunk [0x76970179+25]\n\tRtlGetAppContainerNamedObjectPath [0x771A662D+237]\n\tRtlGetAppContainerNamedObjectPath [0x771A65FD+189]\n"}}
_WD_ExecuteScript: {"value":{"error":"unknown error","message":"Runtime.evaluate threw exception: SyntaxError: Unexpected identifier\n  (Session info: chrome=74.0.3729.131)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00E6DB63+1432419]\n\tOrdinal0 [0x00DE8D81+888193]\n\tOrdinal0 [0x00D8B9D1+506321]\n\tOrdinal0 [0x00D90907+526599]\n\tOrdinal0 [0x00D8D34D+512845]\n\tOrdinal0 [0x00D8D184+512388]\n\tOrdinal0 [0x00D8D562+513378]\n\tOrdinal0 [0x00D47366+226150]\n\tOrdinal0 [0x00D3EA0D+190989]\n\tOrdinal0 [0x00D46D94+224660]\n\tOrdinal0 [0x00D3E8AB+190635]\n\tOrdinal0 [0x00D25F16+89878]\n\tOrdinal0 [0x00D2757A+95610]\n\tOrdinal0 [0x00D27474+95348]\n\tGetHandleVerifier [0x00FCDE7C+1274156]\n\tGetHandleVerifier [0x00F1B6D9+543113]\n\tGetHandleVerifier [0x00F1B4E0+542608]\n\tOrdinal0 [0x00E7B508+1488136]\n\tGetHandleVerifier [0x00F1BC86+544566]\n\tOrdinal0 [0x00DFEEC5+978629]\n\tOrdinal0 [0x00E0B35B+1028955]\n\tOrdinal0 [0x00E0B49F+1029279]\n\tOrdinal0 [0x00E0A445+1025093]\n\tBaseThreadInitThunk [0x76970179+25]\n\tRtlGetAppContainerNamedObjectPath [0x771A662D+237]\n\tRtlGetAppContainerNamedObjectPath [0x771A65FD+189]\n"}}

What am I doing wrong?

Link to comment
Share on other sites

Hello, Danp2!

Why element don't found after send PageDown to browser?

Example 1 - element founded:

$sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//a[@class='btn']")
_WD_ElementAction($sSession, $sElement, 'click')

Example 2 - element not founded:

Send('{PGDN}')
Sleep(1000)
Send('{PGDN}')
Sleep(1000)
$sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//a[@class='btn']")
_WD_ElementAction($sSession, $sElement, 'click')

Why Example 2 don't work?

Link to comment
Share on other sites

Hi at all,

how can I figure out that witch options are belongs to witch select-group (id: pices or id: size)?

For example to order (click) 3 t-shirt's  in size 7 at a web-shop.

 

<select size='1' name='pices' id='pices'>
  <option value='0'>0</option>
  <option value='1' selected>1</option>
  <option value='2'>2</option>
  <option value='3'>3</option>
  <option value='4'>4</option>
  <option value='5'>5</option>
  <option value='6'>6</option>
  <option value='7'>7</option>
  <option value='8'>8</option>
  <option value='9'>9</option>
  <option value='0'>0</option>
</select>

<select size='1' name='size' id='size'>
  <option value='0'>0</option>
  <option value='1' selected>1</option>
  <option value='2'>2</option>
  <option value='3'>3</option>
  <option value='4'>4</option>
  <option value='5'>5</option>
  <option value='6'>6</option>
  <option value='7'>7</option>
  <option value='8'>8</option>
  <option value='9'>9</option>
  <option value='0'>0</option>
</select>

with the command:

$aOptions = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//option", '', True)

I will get all options of both select-groups an each will be double.

 

 

Link to comment
Share on other sites

1 hour ago, Danp2 said:

@Hamburgo Have you tried something like this?

$aOptions = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='size']/option", '', True)

 

@Danp2 Perfect !!!

;))

With the command:    $sText = _WD_ElementAction($sSession, $aOptions[$i], 'text')   I get the text of each option. That is fine.

With the command:    $sValue = _WD_ElementAction($sSession, $aOptions[$i], 'value')   I do NOT get the value of each option. That is bad.

The result is allways: {"value":null}

How do I get the value of each option ?

 

Link to comment
Share on other sites

6 minutes ago, Danp2 said:

@Hamburgo You likely need to use either 'attribute' or  'property' instead of 'value'.

@Danp2 I am tried both out of success. ;((

on "https://kmu-office.spdns.de/TDL/test/" I have a test-page:

 

<select size='1' name='pices' id='pices'>
  <option value='pv0'>pt0</option>
  <option value='pv1' selected>pt1</option>
  <option value='pv2'>pt2</option>
  <option value='pv3'>pt3</option>
  <option value='pv4'>pt4</option>
  <option value='pv5'>pt5</option>
  <option value='pv6'>pt6</option>
  <option value='pv7'>pt7</option>
  <option value='pv8'>pt8</option>
  <option value='pv9'>pt9</option>
</select>
<BR><BR>
<select size='1' name='size' id='size'>
  <option value='sv0'>st0</option>
  <option value='sv1' selected>st1</option>
  <option value='sv2'>st2</option>
  <option value='sv3'>st3</option>
  <option value='sv4'>st4</option>
  <option value='sv5'>st5</option>
  <option value='sv6'>st6</option>
  <option value='sv7'>st7</option>
  <option value='sv8'>st8</option>
  <option value='sv9'>st9</option>
</select>

The text of each option I get, like pt0 to pt9 OR st0 to st9,

but not pv0 to pv9 OR sv0 to sv9.

$aOptions = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//option[contains(@value,'sv')]", '', True)

This command found out of problems all options with value="sv" 0 to 9

Do you have any other proposal ?

Link to comment
Share on other sites

Not sure what you are doing wrong (because you didn't post your code 🙄), but the following works for me --

_WD_Navigate($sSession, "https://kmu-office.spdns.de/TDL/test/")
    $aOptions = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='size']/option", '', True)
    $sValue = _WD_ElementAction($sSession, $aOptions[3], 'attribute', 'value')
    ConsoleWrite($sValue & @crlf)

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...