Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

I tried this:

_WD_ExecuteCdpCommand($sSession,'Page.setDownloadBehavior','{"behavior": "allow", "downloadPath": "D:/"}')

In the log I can see it has been processed:

Quote

[1606202783.862][INFO]: [f2d060d6c8d3b639b77b63f654790aea] COMMAND ExecuteCDP {
   "cmd": "Page.setDownloadBehavior",
   "params": "{\"behavior\": \"allow\", \"downloadPath\": \"D:/\"}"
}

Nevertheless the file is still downloaded to the default folder.

Also tried with

_WD_ExecuteCdpCommand($sSession,'Page.setDownloadBehavior',"{behavior: 'allow', downloadPath: 'D:/'}")

In the log it was

Quote

[1606203265.913][INFO]: [e567bffe6965b2da3dde1eea61bd8945] COMMAND ExecuteCDP {
   "cmd": "Page.setDownloadBehavior",
   "params": "{behavior: 'allow', downloadPath: 'D:/'}"
}

Still, the file was not in the D:/ folder.

Link to comment
Share on other sites

You should be able to use _WD_ExecuteCdpCommand with the Page.setDownloadBehavior command as shown in the python script. I see that this command is deprecated so it may or may not work in the latest version of Chrome.

Edit: Did not notice @AttilaP's reply in this page as my notification took me to the previous page.

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Sorry I searched google, but it did no search deep, when I searched with forum's search, it came up with many answers.

for future references for those looking for disabling save password dialog within chrome, they must add this

"prefs": {"credentials_enable_service": false, "profile.password_manager_enabled": false},

 

Edited by Siwa
Link to comment
Share on other sites

On 11/24/2020 at 2:11 PM, Danp2 said:

@AttilaP It might help if you post a reproducer so that we can fully see what you're doing.

Wish I could.. But the site has credentials, and I think that is the problem.

_WD_DownloadFile has nothing to do with the browser itself, it is calling InetRead(). So the cookies are not passed, therefore I got the logon screen back.

But it is still strange that when I use standard navigation, the file is downloaded - but into the standard downloads folder, not to the one I specify.

Link to comment
Share on other sites

Have you tried the `download.default_directory` Chrome option? You can set a default path for downloads and any downloads will go into that folder.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Just another question, I want to add a timeout to my automation, so if the entire code is stuck at a point, then it will exit after a defined time ( like 2 minutes for example ), so the code can go on. ( My entire code checks for lots of elements and navigates to different pages)

The only way I can think of is he use of TimeDiff. But if then I have to do it during each action performed, so it will be confusing and a lot of unnecessary coding.

I came across _WD_Timeouts but I don't know it's function and what it does even I read the UDF part too. 

What are my solutions besides TimeDiff, for my entire script ? ( combination of "Page load timeout" and "Script timeout" )

Edited by Siwa
Link to comment
Share on other sites

@Siwa AdlibRegister ( "function" [, time = 250] ) is available just for this purpose. You should carefully read the Remarks of the Help file: The adlib function should be kept simple as it is executed often and during this time the main script is paused.
 

AdlibRegister("MyExit")

$h = TimerInit()
While 1
    Sleep(20)
WEnd


Func MyExit()
    If TimerDiff($h) > 5000 Then Exit
EndFunc

 

Edited by CYCho
Link to comment
Share on other sites

@CYCho Adlib will be useful if no other option is not available. I prefer to do it inside webdriver itself or the UDF.

@Danp2 an example is a simple code like :

$All_Cases = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='dataTable_paginator_top']/span[1]")

or any other code, when the page is not loaded fully for a reason like net hiccups or sudden and momentarily net disconnecting's and the page try's to load for a long time, or is stuck at the spinning circle for ever. 

I want to be able to stop and repeat the process if it takes longer than 2 - 3 minutes to finish (obviously there is something going wrong), or load the page or an autoit script to proceed to the next step.

Edited by Siwa
Link to comment
Share on other sites

Hi @Danp2, I am testing if I can migrate my webdriver codes based on chromedriver to msedgedriver. But I am stuck in my first step. When I run the following code, the Edge browser displays a modal dialogue box asking me if I want to sync my profile. This dialogue is not detected by _WD_Alert and "unhandledPromptBehavior": "ignore" clause in the capabilities does not have any effect. Please help me on how I can handle this dialogue box.
 

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

_WD_Option('Driver', @ScriptDir & '\msedgedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\msedge.log"')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"unhandledPromptBehavior": "ignore", ' & _
    '"ms:edgeOptions": {"excludeSwitches": ["enable-automation"], ' & _
    '"useAutomationExtension": false, "args": ["start-maximized"]}}}}'

$_WD_DEBUG = $_WD_Debug_Info ; None ; Info
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
Sleep(1000)

_WD_Navigate($sSession, "https://www.autoitscript.com")

The SciTE console looks like this:

>Running:(3.3.14.5):C:\AutoIt3\autoit3.exe "D:\EdgeDriver\EdgeTest.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
_WD_IsLatestRelease: True
_WD_IsLatestRelease ==> Success
_WDStartup: OS: WIN_10 WIN32_NT 19042 
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.3.1.0 (Up to date)
_WDStartup: WinHTTP:    1.6.4.2
_WDStartup: Driver: D:\EdgeDriver\msedgedriver.exe
_WDStartup: Params: --verbose --log-path="D:\EdgeDriver\msedge.log"
_WDStartup: Port:   9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"unhandledPromptBehavior": "ignore", "ms:edgeOptions": {"excludeSwitches": ["enable-automation"], "useAutomationExtension": false, "args": ["start-maximized"]}}}}
__WD_Post: StatusCode=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"msedge","browserVersion":"87.0....
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"msedge","browserVersion":"87.0.664.57","ms:edgeOptions":{"debuggerAddress":"localhost:61768"},"msedge":{"msedgedriverVersion":"86.0.622.68 (48323fbb4a373465cd5175c727ef318acbd46c33)","userDataDir":"C:\\Users\\CYCho\\AppData\\Local\\Temp\\scoped_dir13840_1521216339"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"ignore","webauthn:virtualAuthenticators":true},"sessionId":"9e38fc90e6147bc2c9916ab2a74efdb6"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/9e38fc90e6147bc2c9916ab2a74efdb6/url; $sData={"url":"https://www.autoitscript.com"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Navigate: {"value":null}

 

image.png.e3a22705bfd39b6130f6a92e1cdbb897.png

Edited by CYCho
Link to comment
Share on other sites

Hi all. 

Im new to AutoIT and the webdriver UDF so bear with me :) 

I have tried to search a bit in the forum but have not succeeded in finding something that works for me. 

I am trying to open a website and respond to the "popup" by clicking accept. 

 

image.thumb.png.b7baa750d15b0529af875df031e50c9b.png

My strategy has been to first identify the element by: 

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='agree']")

And then click the button by 

_WD_ElementAction($sSession,$sElement,'click')

But it seems like the webdriver cannot find the element

 

_WDStartup: OS:    WIN_10 WIN32_NT 18363 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.2.0.5
_WDStartup: WinHTTP:    1.6.4.1
_WDStartup: Driver:    S:\AutoITInclude\chromedriver.exe
_WDStartup: Params:    --verbose --log-path="S:\AutoIT_tutorial\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":"87.0.4280.88","chrome":{"chromedriverVersion":"87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})","userDataDir":"C:\\Users\\abodi\\AppData\\Local\\Temp\\scoped_dir51416_1944427882"},"goog:chromeOptions":{"debuggerAddress":"localhost:59821"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:virtualAuthenticators":true},"sessionId":"2afc622222c767b8fbab1613c58f938d"}}
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"87.0.4280.88","chrome":{"chromedriverVersion":"87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761})","userDataDir":"C:\\Users\\abodi\\AppData\\Local\\Temp\\scoped_dir51416_1944427882"},"goog:chromeOptions":{"debuggerAddress":"localhost:59821"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:virtualAuthenticators":true},"sessionId":"2afc622222c767b8fbab1613c58f938d"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/2afc622222c767b8fbab1613c58f938d/url; $sData={"url":"http://finance.yahoo.com"}
__WD_Post: StatusCode=200; ResponseText={"value":null}
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/2afc622222c767b8fbab1613c58f938d/element; $sData={"using":"xpath","value":"//select[@name='agree']"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//select[@name='agree']\"}\n  (Session info: chrome=87.0.4280.88)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0106C0C3+3326147]\n\tOrdinal0 [0x00F50851+2164817]\n\tOrdinal0 [0x00DD7298+619160]\n\tOrdinal0 [0x00D5C070+114800]\n\tOrdinal0 [0x00D7FC42+261186]\n\tOrdinal0 [0x00D71A2A+203306]\n\tOrdinal0 [0x00D7E559+255321]\n\tOrdinal0 [0x00D7189B+202907]\n\tOrdinal0 [0x00D53DF4+81396]\n\tOrdinal0 [0x00D54DEE+85486]\n\tOrdinal0 [0x00D54D79+85369]\n\tOrdinal0 [0x00F685DC+2262492]\n\tGetHandleVerifier [0x011F2874+1487204]\n\tGetHandleVerifier [0x011F23CD+1486013]\n\tGetHandleVerifier [0x011FA368+1518680]\n\tGetHandleVerifier [0x011F2F4E+1488958]\n\tOrdinal0 [0x00F5ED0D+2223373]\n\tOrdinal0 [0x00F6A12B+2269483]\n\tOrdinal0 [0x00F6A26F+2269807]\n\tOrdinal0 [0x00F7ECB8+2354360]\n\tBaseThreadInitThunk [0x774A6359+25]\n\tRtlGetAppContainerNamedObjectPath [0x775F8944+228]\n\tRtlGetAppContainerNamedObjectPath [0x775F8914+180]\n"}}
_WD_FindElement: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//select[@name='agree']\"}\n  (Session info: chrome=87.0.4280.88)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0106C0C3+3326147]\n\tOrdinal0 [0x00F50851+2164817]\n\tOrdinal0 [0x00DD7298+619160]\n\tOrdinal0 [0x00D5C070+114800]\n\tOrdinal0 [0x00D7FC42+261186]\n\tOrdinal0 [0x00D71A2A+203306]\n\tOrdinal0 [0x00D7E559+255321]\n\tOrdinal0 [0x00D7189B+202907]\n\tOrdinal0 [0x00D53DF4+81396]\n\tOrdinal0 [0x00D54DEE+85486]\n\tOrdinal0 [0x00D54D79+85369]\n\tOrdinal0 [0x00F685DC+2262492]\n\tGetHandleVerifier [0x011F2874+1487204]\n\tGetHandleVerifier [0x011F23CD+1486013]\n\tGetHandleVerifier [0x011FA368+1518680]\n\tGetHandleVerifier [0x011F2F4E+1488958]\n\tOrdinal0 [0x00F5ED0D+2223373]\n\tOrdinal0 [0x00F6A12B+2269483]\n\tOrdinal0 [0x00F6A26F+2269807]\n\tOrdinal0 [0x00F7ECB8+2354360]\n\tBaseThreadInitThunk [0x774A6359+25]\n\tRtlGetAppContainerNamedObjectPath [0x775F8944+228]\n\tRtlGetAppContainerNamedObjectPath [0x775F8914+180]\n"}}
_WD_FindElement ==> No match: HTTP status = 404
"S:\AutoIT_tutorial\FindTrickerNames.au3" (95) : ==> Error parsing function call.:
_WD_Shutdown

Link to comment
Share on other sites

1 hour ago, CYCho said:

When I run the following code, the Edge browser displays a modal dialogue box asking me if I want to sync my profile.

I ran your code, but didn't encounter this dialog. Suggest that you try to identify what is causing this to appear.

It likely won't have any effect on this issue, but your msedgedriver appears to be out of date.

Link to comment
Share on other sites

1 hour ago, Danp2 said:

I ran your code, but didn't encounter this dialog. Suggest that you try to identify what is causing this to appear.

It likely won't have any effect on this issue, but your msedgedriver appears to be out of date.

I updated both Edge and msedgedriver to the latest matching versions and, as you expected, it was not an issue. The dialogue box appears when the session is created before navigating to a web site. Until I find an answer, I will just issue a Send("{enter}") command, which basically accepts the prompt, and go on with further tests. Please let me know if you come across with a solution.

Sync_Your_Profile.png

Edited by CYCho
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...