Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

10 hours ago, Danp2 said:

Pretty sure that's the wrong code for an 'n'. 😉

Yes, I copied wrong line... that is Unicode corresponding to "f": I tried also this to see if it can open the search on chrome => nothing.

Anyway, before, I tried with "n" and also with the corresponding "\u006E".

;~ $sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE009"}, {"type": "keyDown", "value": "\u0066"},{"type": "keyUp", "value": "\u0066"}, {"type": "keyUp", "value": "\uE009"}]}]}'
;~ $sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE009"}, {"type": "keyDown", "value": "\u006E"},{"type": "keyUp", "value": "\u006E"}, {"type": "keyUp", "value": "\uE009"}]}]}'
$sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE009"}, {"type": "keyDown", "value": "n"},{"type": "keyUp", "value": "n"}, {"type": "keyUp", "value": "\uE009"}]}]}'
_WD_Action($sSession, 'actions', $sAction)

None works.

Edited by frank10
Link to comment
Share on other sites

Hello, I've got a problem with my script. My Chromedriver is the same version as my Chrome. 

Script:

#include "wd_core.au3"
#include "wd_helper.au3"
Local $sDesiredCapabilities, $sSession
SetupChrome()

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.facebook.com")
_ChromeSetInputValueById($sSession,'email','abc')
_ChromeSetInputValueById($sSession,'pass','xyz')
_WD_Shutdown()

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

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":[' & """start-maximized""," & " ""disable-infobars""" & "" & '] }}}}'
EndFunc   ;==>SetupChrome
Func _ChromeSetInputValueById($sSession,$Id,$Value)
 $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']")
 _WD_ElementAction($sSession,$sButton,'value', $Value)
EndFunc

Log:

[1614167119.855][INFO]: Starting ChromeDriver 88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324@{#1784}) on port 9515
[1614167119.855][INFO]: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[1614167120.177][INFO]: [78caf00f76200627afac9dda295f2065] COMMAND InitSession {
   "capabilities": {
      "alwaysMatch": {
         "chromeOptions": {
            "args": [ "start-maximized", "disable-infobars" ],
            "w3c": true
         }
      }
   }
}
[1614167120.186][INFO]: [78caf00f76200627afac9dda295f2065] RESPONSE InitSession ERROR invalid argument: unrecognized capability: chromeOptions

What's wrong with my Chrome options? 

Link to comment
Share on other sites

@Paulliev,

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"], ' & _
    '"useAutomationExtension": false, "args": ["start-maximized"] }}}}'

Please take a look at wd_demo.au3. "chromeOptions" should be preceded by company designation like "goog:chroemOptions" and "ms:edgeOptions". "disable-infobars" was desprecated quite while ago and now you can use "excludeSwitches": ["enable-automation"], "useAutomationExtension": false instead. These changes have been discussed in this forum. 

Edited by CYCho
Link to comment
Share on other sites

Hi @Danp2 and everyone on this thread -- it's been awhile since I have been to the forum, but spent a few days catching up where I could.

Thanks in advance for any help you can provide.

I cannot get a form to submit with the following code:
 

 _WD_Startup()

   If @error <> $_WD_ERROR_Success Then
       Exit -1
   EndIf

   $sSession = _WD_CreateSession($sDesiredCapabilities)
   _WD_Navigate($sSession, "https://www.fedex.com/apps/onlineclaims/?locale=en_US")
   _WD_LoadWait($sSession, 3000)

   $Tracking_Number = '962515408056'
   $Lost_Damaged = "Shipment not received"

   $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sElementSelector)
   $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div/input", Default, True)
   _WD_ElementAction($sSession, $aElements[1], 'value', $Tracking_Number)

   $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div/select", Default, True)
   _WD_ElementAction($sSession, $aElements[0], 'value', $Lost_Damaged)


   $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div/button", Default, True)
   _WD_ElementAction($sSession, $aElements[1], 'click')

   MsgBox(0,"stop here","")

   _WD_DeleteSession($sSession)
   _WD_Shutdown()

 

The console readout is:

_WD_IsLatestRelease: True
_WD_IsLatestRelease ==> Success
_WDStartup: OS: WIN_10 WIN32_NT 19041 
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.4.0.1 (Up to date)
_WDStartup: WinHTTP:    1.6.4.2
_WDStartup: Driver: C:\FCI\Resources\ChromeDriver\chromedriver.exe
_WDStartup: Params: --verbose --log-path="C:\FCI\Claims\FedEx_Claim_Forms\Scripts\chrome.log"
_WDStartup: Port:   9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}
__WD_Post: StatusCode=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"88.0....
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"88.0.4324.182","chrome":{"chromedriverVersion":"88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324@{#1784})","userDataDir":"C:\\Users\\SA\\AppData\\Local\\Temp\\scoped_dir2772_1264260059"},"goog:chromeOptions":{"debuggerAddress":"localhost:59442"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:extension:largeBlob":true,"webauthn:virtualAuthenticators":true},"sessionId":"1a5df9600f563207dc754e0b626f22f4"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/1a5df9600f563207dc754e0b626f22f4/url; $sData={"url":"https://www.fedex.com/apps/onlineclaims/?locale=en_US"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/1a5df9600f563207dc754e0b626f22f4/execute/sync; $sData={"script":"return document.readyState", "args":[]}
__WD_Post: StatusCode=200; ResponseText={"value":"complete"}...
_WD_ExecuteScript: {"value":"complete"}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/1a5df9600f563207dc754e0b626f22f4/element; $sData={"using":"xpath","value":"//input[@name='q']"}
__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\":\"xpath\",\"selector\":\"//input[@name='q']\"}\n  (Session info: chrome=88.0.4324.182)","stacktrace":"Backtrace:\n\tGetHandleVerifier [0x00E0B963+483]\n\tGetHandleVerifier [0x00E0B941+449]\n\tGetHandleVerifier [0x011B3308+3832712]\n\tGetHandleVerifier [0x011D61C4+3975748]\n\tGetHandleVerifier [0x011F8822+4116642]\n\tGetHandleVerifier [0x011EB43A+4062394]\n\tGetHandleVerifier [0x011F7159+4110809]\n\tGetHandleVerifier [0x011EB2EB+4062059]\n\tGetHandleVerifier [0x011CED14+3945876]\n\tGetHandleVerifier [0x011CFBCE+3949646]\n\tGetHandleVerifier [0x011CFB59+3949529]\n\tOrdinal0 [0x00DCB5CC+46540]\n\tOrdinal0 [0x00DC9F53+40787]\n\tOrdinal0 [0x00DC9B12+39698]\n\tGetHandleVerifier [0x010D1468+2907368]\n\tGetHandleVerifier [0x00F171EE+1096302]\n\tGetHandleVerifier [0x00ED3E8D+821005]\n\tGetHandleVerifier [0x00ED396B+819691]\n\tGetHandleVerifier [0x00ED3881+819457]\n\tGetHandleVerifier [0x00EFF463+998627]\n\tBaseThreadInitThunk [0x75E7FA29+25]\n\tRtlGetAppContainerNamedObjectPath [0x778976B4+228]\n\tRtlGetAppContainerNamedObjectPath [0x77897684+180]\n"}}
_WD_FindElement: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//input[@name='q']\"}\n  (Session info: chrome=88.0.4324.182)","stacktrace":"Backtrace:\n\tGetHandleVerifier [0x00E0B963+483]\n\tGetHandleVerifier [0x00E0B941+449]\n\tGetHandleVerifier [0x011B3308+3832712]\n\tGetHandleVerifier [0x011D61C4+3975748]\n\tGetHandleVerifier [0x011F8822+4116642]\n\tGetHandleVerifier [0x011EB43A+4062394]\n\tGetHandleVerifier [0x011F7159+4110809]\n\tGetHandleVerifier [0x011EB2EB+4062059]\n\tGetHandleVerifier [0x011CED14+3945876]\n\tGetHandleVerifier [0x011CFBCE+3949646]\n\tGetHandleVerifier [0x011CFB59+3949529]\n\tOrdinal0 [0x00DCB5CC+46540]\n\tOrdinal0 [0x00DC9F53+40787]\n\tOrdinal0 [0x00DC9B12+39698]\n\tGetHandleVerifier [0x010D1468+2907368]\n\tGetHandleVerifier [0x00F171EE+1096302]\n\tGetHandleVerifier [0x00ED3E8D+821005]\n\tGetHandleVerifier [0x00ED396B+819691]\n\tGetHandleVerifier [0x00ED3881+819457]\n\tGetHandleVerifier [0x00EFF463+998627]\n\tBaseThreadInitThunk [0x75E7FA29+25]\n\tRtlGetAppContainerNamedObjectPath [0x778976B4+228]\n\tRtlGetAppContainerNamedObjectPath [0x77897684+180]\n"}}
_WD_FindElement ==> No match: HTTP status = 404
__WD_Post: URL=HTTP://127.0.0.1:9515/session/1a5df9600f563207dc754e0b626f22f4/elements; $sData={"using":"xpath","value":"//div/input"}
__WD_Post: StatusCode=200; ResponseText={"value":[{"element-6066-11e4-a52e-4f735466cecf":"77c9900e-c8d3-45ea-9cdf-cf1726b6e777"},{"element-6...
_WD_FindElement: {"value":[{"element-6066-11e4-a52e-4f735466cecf":"77c9900e-c8d3-45ea-9cdf-cf1726b6e777"},{"element-6066-11e4-a52e-4f735466cecf":"a4b87814-fb24-478c-968c-a7c52de5d106"}]}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/1a5df9600f563207dc754e0b626f22f4/element/a4b87814-fb24-478c-968c-a7c52de5d106/value; $sData={"id":"a4b87814-fb24-478c-968c-a7c52de5d106", "text":"962515408056"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_ElementAction: {"value":null}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/1a5df9600f563207dc754e0b626f22f4/elements; $sData={"using":"xpath","value":"//div/select"}
__WD_Post: StatusCode=200; ResponseText={"value":[{"element-6066-11e4-a52e-4f735466cecf":"210eadec-f359-4bb2-8a5c-8a8397dd3141"}]}...
_WD_FindElement: {"value":[{"element-6066-11e4-a52e-4f735466cecf":"210eadec-f359-4bb2-8a5c-8a8397dd3141"}]}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/1a5df9600f563207dc754e0b626f22f4/element/210eadec-f359-4bb2-8a5c-8a8397dd3141/value; $sData={"id":"210eadec-f359-4bb2-8a5c-8a8397dd3141", "text":"Shipment not received"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_ElementAction: {"value":null}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/1a5df9600f563207dc754e0b626f22f4/elements; $sData={"using":"xpath","value":"//div/button"}
__WD_Post: StatusCode=200; ResponseText={"value":[{"element-6066-11e4-a52e-4f735466cecf":"00683a4b-44f5-4562-9864-89dd46852cba"},{"element-6...
_WD_FindElement: {"value":[{"element-6066-11e4-a52e-4f735466cecf":"00683a4b-44f5-4562-9864-89dd46852cba"},{"element-6066-11e4-a52e-4f735466cecf":"5d259e27-07f2-4050-ab3a-d70aefce370f"},{"element-6066-11e4-a52e-4f735466cecf":"7b735cde-df58-46d7-a5b5-883348cbc25c"},{"element-6066-11e4-a52e-4f735466cecf":"414c94b7-3d30-46dc-add2-52ebf7a36b75"}]}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/1a5df9600f563207dc754e0b626f22f4/element/5d259e27-07f2-4050-ab3a-d70aefce370f/click; $sData={"id":"5d259e27-07f2-4050-ab3a-d70aefce370f"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_ElementAction: {"value":null}...

 

Chromedriver readout:

 

Starting ChromeDriver 88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324@{#1784}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

DevTools listening on ws://127.0.0.1:59442/devtools/browser/43d415b1-80af-474a-972e-7ab5aec857b6
[1404:5792:0224/132921.875:ERROR:device_event_log_impl.cc(211)] [13:29:21.874] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[1404:5792:0224/132921.876:ERROR:device_event_log_impl.cc(211)] [13:29:21.875] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[1404:5792:0224/132921.878:ERROR:device_event_log_impl.cc(211)] [13:29:21.878] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)

 

When I manually visit the website and enter the tracking number and claim type, I can get past the continue button and on to the next screen where I will need to hit another continue button, as seen in the attached screen shot. For now, I am just trying to get past the first page....

 

Also, please see the attached chrome log file.

 

Thank you again for your help!

 

 

 

fedex_claims_continue.png

 

chrome.log

Edited by NSearch
Link to comment
Share on other sites

@NSearch There are a few issues I can see --

  • You left the following line in your code
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sElementSelector)
  • The above likely explains why your console readout doesn't match the posted code (no find for //input[@name='q'])
  • This website appears to be detecting / blocking the use of webdriver. You can confirm this yourself by manually filing in the fields and clicking the Continue button after launching the browser under webdriver control
Link to comment
Share on other sites

@Danp2, Yes, you're right, I accidently left that line of code in.....I was thinking of editing, but maybe someone else will find this mistake useful.

For the second point, I attempted manually after wd_navigate and got the same result.

Do you have any recommendations on what I could do now?

Link to comment
Share on other sites

@NSearch This works for me --

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

Local $sDesiredCapabilities, $sSession

SetupChrome()
_WD_Startup()

If @error <> $_WD_ERROR_Success Then
   Exit -1
EndIf

$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.fedex.com/apps/onlineclaims/?locale=en_US")
_WD_LoadWait($sSession, 3000)

$Tracking_Number = '962515408056'
$Lost_Damaged = "Shipment not received"

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='trackingNumber']")
_WD_ElementAction($sSession, $sElement, 'value', $Tracking_Number)

_WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//div/select/option[@value='LC']")
_WD_LoadWait($sSession, 3000)

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='tracking_nbr_cont_btn']")
_WD_ElementAction($sSession, $sElement, 'click')

MsgBox(0,"stop here","")

_WD_DeleteSession($sSession)
_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":["--disable-blink-features=AutomationControlled"]}}}}'
EndFunc   ;==>SetupChrome

Note --

  • The argument passed in the DesiredCapacities string helped
  • Without the 2nd _WD_LoadWait, the website still didn't function properly
Link to comment
Share on other sites

20210302015214.png.4180d4ee38252adf20da25fe2af29e4f.png

最近遇到了一个问题
,几个div标签的类名是一个“模态淡入”的类名(带空格),但是
当div激活时不是复合类名,它的类名变成了“模态淡入”。
如果要通过Xpath定位div元素,则出现错误:

https://getbootstrap.com/docs/4.0/components/modal/
本地$ sActiveModal = _WD_FindElement($ sSession,'xpath''// div [@ class =“ modal fade in”]') 
如果$ sActiveModal,则ConsoleWrite'捕获到模式淡入。'@CRLF
_WD_FindElement:{“值”:{“错误”:“没有这样的元素”,“消息”:“没有这样的元素:无法找到元素:{\”方法\“:\” xpath \“,\”选择器\“ :\“ // div [@ class = \”模式淡入\“] \”} \ n(会话信息:chrome = 88.0.4324.190)“,” stacktrace“:”回溯:\ n \ tGetHandleVerifier [0x00B7B963 + 483] \ n \ tGetHandleVerifier [0x00B7B941 + 449] \ n \ tGetHandleVerifier [0x00F23308 + 3832712] \ n \ tGetHandleVerifier [0x00F461C4 + 3975748] \ n \ tGetHandleVerifier [4x00F642 0x00F5B43A + 4062394] \ n \ tGetHandleVerifier [0x00F67159 + 4110809] \ n \ tGetHandleVerifier [0x00F5B2EB + 4062059] \ n \ tGetHandleVerifier [0x00F3ED14 + 3945876] \ n \ tGetHandleVerifier [0x00F3FBCE + 646] n \ tOrdinal0 [0x00B3B5CC + 46540] \ n \ tOrdinal0 [0x00B39F53 + 40787] \ n \ tOrdinal0 [0x00B39B12 + 39698] \ n \ tGetHandleVerifier [0x00E41468 + 2907368] \ n \ tGetHandleVerifier [0x00C871EE] [+ 1] +821005] \ n \ tGetHandleVerifier [0x00C4396B + 819691] \ n \ tGetHandleVerifier [0x00C43881 + 819457] \ n \ tGetHandleVerifier [0x00C6F463 + 998627] \ n \ tBaseThreadInitThunk[0x7718ED6C + 18] \ n \ tRtlInitializeExceptionChain [0x777B37EB + 239] \ n \ tRtlInitializeExceptionChain [0x777B37BE + 194] \ n“}}

如何通过带有空格的类名找到元素?

 

Edited by Letraindusoir
Link to comment
Share on other sites

38 minutes ago, Danp2 said:

@Letraindusoir Seems you've left out some important details. Those DIVs are containers for modal dialogs that aren't visible unless you click on one of the buttons. Is the modal dialog visible when you call _WD_FindElement?

Yes, my intention is, after clicking the modal box button to activate it.

when the modal box is activated, identify it by Xpath for other subsequent actions

Because modal boxes can have no more than one,

but only one in active state  with the classname "modal fade in".

by identifying the div with classname "modal fade in",some follow-up actions can be done.

There are examples on this website page:

https://getbootstrap.com/docs/4.0/components/modal/

 

It seems difficult to identify element by classname with spaces....

Edited by Letraindusoir
Link to comment
Share on other sites

Hello, I want to use a function to set a dropdown option by the value. But does the _WD_ElementOptionSelect function still exist? Because my script says he couldn't find the function.

$Prioriteit = _WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "/select[@name='custom_field_39021']/option[contains(text(),'Normaal (hinder)')]")
_WD_ElementAction($sSession, $Prioriteit, 'click')

 

Link to comment
Share on other sites

This is what I Include.

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

_WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "/select[@name='custom_field_39021']/option[contains(text(),'Normaal (hinder)')]")

This should do it right? It still says Error: Unknown function name. Can't find the functions in one of the included files either.

Edited by Paulliev
Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...