Siwa Posted November 22, 2020 Posted November 22, 2020 It did not work, and I added _WD_GetFrameCount($sSession) which returned 0. How can I check for frames or iframes inside he html ?
AttilaP Posted November 22, 2020 Posted November 22, 2020 Hello! With this addon I can start Chrome headless (by passing --headless to args in $sDesiredCapabilities). Is there any way to show the window later on different conditions? Or once it started without the UI, it will not be visible anymore?
Siwa Posted November 22, 2020 Posted November 22, 2020 1 hour ago, AttilaP said: Hello! With this addon I can start Chrome headless (by passing --headless to args in $sDesiredCapabilities). Is there any way to show the window later on different conditions? Or once it started without the UI, it will not be visible anymore? I guess you can do that by using WInsetState, but you have to get the handle of the windows first.
Danp2 Posted November 22, 2020 Author Posted November 22, 2020 @AttilaP Haven't tried, but I always assumed that a headless session will always be headless. Latest Webdriver UDF Release Webdriver Wiki FAQs
Danp2 Posted November 22, 2020 Author Posted November 22, 2020 @Siwa Have you checked out the ChroPath extension? Siwa 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
AttilaP Posted November 22, 2020 Posted November 22, 2020 14 minutes ago, Danp2 said: @AttilaP Haven't tried, but I always assumed that a headless session will always be headless. And it is possible to start "normally" and then hide the Window?🤔
Danp2 Posted November 22, 2020 Author Posted November 22, 2020 @AttilaP I imagine it's possible using standard Autoit commands, but haven't tested to see what effect it will have on the webdriver functionality, if any. Latest Webdriver UDF Release Webdriver Wiki FAQs
Nine Posted November 22, 2020 Posted November 22, 2020 1 hour ago, AttilaP said: and then hide the Window? Here what I do : _WD_WINDOW($sSession, "rect", '{"x":-1000,"y":-1000,"width":500,"height":500}') AttilaP 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
Siwa Posted November 22, 2020 Posted November 22, 2020 I installed it and the result is the same. I tried the element by id, by class, by name .... but with no success in clicking the button, or reading the ui. If I get the position of the element, can I send a mouse click to the location ? because the ui dialog is placed middle no matter of my scroll. and I want to be headless, so MouseCLick() is not an option for me, I want the webdriver to the clicking.
Danp2 Posted November 22, 2020 Author Posted November 22, 2020 @Siwa Can you provide a link to the website? If not, then how about finding another site with the same type of dialog? FWIW, I suspect that you are dealing with a jQuery Dialog like this, but can't tell for sure based on info provided. Siwa 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
Danp2 Posted November 22, 2020 Author Posted November 22, 2020 @Siwa The link you sent me via PM won't load for me. Not sure why... maybe limited access geographically. <shrug> Maybe this will help you -- #include <wd_core.au3> Local $sDesiredCapabilities SetupChrome() _WD_Startup() Local $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://cdn.rawgit.com/salmanarshad2000/demos/v1.0.4/jquery-ui-dialog/modal-dialog-with-buttons.html") Local $oElement1 = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//div[@class='ui-dialog-buttonset']/button[1]") Local $oElement2 = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//div[@class='ui-dialog-buttonset']/button[2]") _WD_ElementAction($sSession, $oElement1, 'click') Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}' EndFunc Siwa 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
Siwa Posted November 22, 2020 Posted November 22, 2020 (edited) It did not work, and this is the console : Spoiler __WD_Post: URL=HTTP://127.0.0.1:9515/session/03801389c6069e2bb080dae7d55d802f/element; $sData={"using":"xpath","value":"//*[@id='j_idt250']"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"1a414e59-c9f0-430a-a98c-4ec010ce78db"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"1a414e59-c9f0-430a-a98c-4ec010ce78db"}} __WD_Post: URL=HTTP://127.0.0.1:9515/session/03801389c6069e2bb080dae7d55d802f/element/1a414e59-c9f0-430a-a98c-4ec010ce78db/click; $sData={"id":"1a414e59-c9f0-430a-a98c-4ec010ce78db"} __WD_Post: StatusCode=400; ResponseText={"value":{"error":"element not interactable","message":"element not interactable\n (Session info: c... __WD_Post ==> Element interaction issue: {"value":{"error":"element not interactable","message":"element not interactable\n (Session info: chrome=87.0.4280.66)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0085ECE3+3337443]\n\tOrdinal0 [0x0073F041+2158657]\n\tOrdinal0 [0x005C6E50+618064]\n\tOrdinal0 [0x0054CC0B+117771]\n\tOrdinal0 [0x00545B67+88935]\n\tOrdinal0 [0x00561973+203123]\n\tOrdinal0 [0x00545996+88470]\n\tOrdinal0 [0x00561A5A+203354]\n\tOrdinal0 [0x0056E4A9+255145]\n\tOrdinal0 [0x0056181B+202779]\n\tOrdinal0 [0x00543D74+81268]\n\tOrdinal0 [0x00544D6E+85358]\n\tOrdinal0 [0x00544CF9+85241]\n\tOrdinal0 [0x00756F2C+2256684]\n\tGetHandleVerifier [0x009E2FAC+1478332]\n\tGetHandleVerifier [0x009E2AFD+1477133]\n\tGetHandleVerifier [0x009EAAD8+1509864]\n\tGetHandleVerifier [0x009E369E+1480110]\n\tOrdinal0 [0x0074D6BD+2217661]\n\tOrdinal0 [0x007589AB+2263467]\n\tOrdinal0 [0x00758AEF+2263791]\n\tOrdinal0 [0x0076D363+2347875]\n\tBaseThreadInitThunk [0x75D06359+25]\n\tRtlGetAppContainerNamedObjectPath [0x776F7B74+228]\n\tRtlGetAppContainerNamedObjectPath [0x776F7B44+180]\n"}} _WD_ElementAction: {"value":{"error":"element not interactable","message":"element not interactable\n (Session info: c... _WD_ElementAction ==> Element interaction issue: {"value":{"error":"element not interactable","message":"element not interactable\n (Session info: chrome=87.0.4280.66)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0085ECE3+3337443]\n\tOrdinal0 [0x0073F041+2158657]\n\tOrdinal0 [0x005C6E50+618064]\n\tOrdinal0 [0x0054CC0B+117771]\n\tOrdinal0 [0x00545B67+88935]\n\tOrdinal0 [0x00561973+203123]\n\tOrdinal0 [0x00545996+88470]\n\tOrdinal0 [0x00561A5A+203354]\n\tOrdinal0 [0x0056E4A9+255145]\n\tOrdinal0 [0x0056181B+202779]\n\tOrdinal0 [0x00543D74+81268]\n\tOrdinal0 [0x00544D6E+85358]\n\tOrdinal0 [0x00544CF9+85241]\n\tOrdinal0 [0x00756F2C+2256684]\n\tGetHandleVerifier [0x009E2FAC+1478332]\n\tGetHandleVerifier [0x009E2AFD+1477133]\n\tGetHandleVerifier [0x009EAAD8+1509864]\n\tGetHandleVerifier [0x009E369E+1480110]\n\tOrdinal0 [0x0074D6BD+2217661]\n\tOrdinal0 [0x007589AB+2263467]\n\tOrdinal0 [0x00758AEF+2263791]\n\tOrdinal0 [0x0076D363+2347875]\n\tBaseThreadInitThunk [0x75D06359+25]\n\tRtlGetAppContainerNamedObjectPath [0x776F7B74+228]\n\tRtlGetAppContainerNamedObjectPath [0x776F7B44+180]\n"}} __WD_Post: URL=HTTP://127.0.0.1:9515/session/03801389c6069e2bb080dae7d55d802f/execute/sync; $sData={"script":"return document.readyState", "args":[]} __WD_Post: StatusCode=200; ResponseText={"value":"complete"}... _WD_ExecuteScript: {"value":"complete"}... Edit : Finally I got it working by : _WD_ExecuteScript($sSession,"document.getElementById('j_idt250').click();") Glad to solve it finally, and learned how to use JS scripts the right way 😉 (I guess it will be a huge step forward for new learners like me, if you could include this as a example in your demo ) Edited November 22, 2020 by Siwa
Danp2 Posted November 22, 2020 Author Posted November 22, 2020 @Siwa Not sure why the javascript worked where the standard click didn't, but glad you found a solution. FWIW, the control is being found successfully, but the click attempt is failing with "element not interactable". From the webdriver specs -- Quote Error Code HTTP Status JSON Error Code Description element not interactable 400 element not interactable A command could not be completed because the element is not pointer- or keyboard interactable. Siwa 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
Danp2 Posted November 22, 2020 Author Posted November 22, 2020 @Siwa It's possible that the element wasn't visible / enabled, which would cause the issue you encountered. Does it work when you do this? $Confirm_Button = _WD_WaitElement($sSession,$_WD_LOCATOR_ByXPath,"//*[@id='j_idt250']", Default, Default, True, True, True) _WD_ElementAction($sSession, $Confirm_Button, 'click') Latest Webdriver UDF Release Webdriver Wiki FAQs
AttilaP Posted November 23, 2020 Posted November 23, 2020 Hi! I am pretty new to this UDF and I try to fill a login form with it, using ChromeDriver. However, it always replace the @ sign in the username to the text what I have on my clipboard. ChromeDriver 86.0.4240.22 AutoIt 3.3.14.5 A minimalistic code to reproduce this behavior: #include "wd_core.au3" #include "wd_helper.au3" $_WD_DEBUG = $_WD_DEBUG_None $_WD_DEBUG = $_WD_DEBUG_Info _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}' _WD_Startup() If @error <> $_WD_ERROR_Success Then Exit -1 EndIf $sSession = _WD_CreateSession($sDesiredCapabilities) $username = "user@test.com" _WD_Navigate($sSession, "https://www.w3schools.com/html/html_forms.asp") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//input[@id="fname"]'); _WD_ElementAction($sSession, $sElement, 'value', $username); Sleep(15000) _WD_DeleteSession($sSession) _WD_Shutdown() Exit First I copied the text 'CLIPBOARD' to the clipboard with Ctrl+C, then run the above - the result is attached. I see the following in the chrome.log: [1606145142.741][INFO]: Cannot switch to US keyboard layout - some keys may be interpreted incorrectly And below the following, after the letter 'r' in user: Spoiler [1606145148.091][DEBUG]: DevTools WebSocket Command: Input.dispatchKeyEvent (id=61) BCA32ABAF10344BBC3E00EFCD9DC77B9 { "code": "ControlLeft", "key": "Control", "modifiers": 0, "text": "", "type": "rawKeyDown", "unmodifiedText": "", "windowsVirtualKeyCode": 17 } [1606145148.092][DEBUG]: DevTools WebSocket Command: Input.dispatchKeyEvent (id=62) BCA32ABAF10344BBC3E00EFCD9DC77B9 { "code": "AltLeft", "key": "Alt", "modifiers": 0, "text": "", "type": "rawKeyDown", "unmodifiedText": "", "windowsVirtualKeyCode": 18 } [1606145148.092][DEBUG]: DevTools WebSocket Command: Input.dispatchKeyEvent (id=63) BCA32ABAF10344BBC3E00EFCD9DC77B9 { "code": "KeyV", "commands": [ "Paste" ], "key": "v", "modifiers": 3, "text": "@", "type": "rawKeyDown", "unmodifiedText": "v", "windowsVirtualKeyCode": 86 } [1606145148.092][DEBUG]: DevTools WebSocket Command: Input.dispatchKeyEvent (id=64) BCA32ABAF10344BBC3E00EFCD9DC77B9 { "code": "KeyV", "commands": [ "Paste" ], "key": "v", "modifiers": 3, "text": "@", "type": "char", "unmodifiedText": "v", "windowsVirtualKeyCode": 86 } [1606145148.093][DEBUG]: DevTools WebSocket Command: Input.dispatchKeyEvent (id=65) BCA32ABAF10344BBC3E00EFCD9DC77B9 { "code": "KeyV", "commands": [ "Paste" ], "key": "v", "modifiers": 3, "text": "@", "type": "keyUp", "unmodifiedText": "v", "windowsVirtualKeyCode": 86 } [1606145148.093][DEBUG]: DevTools WebSocket Command: Input.dispatchKeyEvent (id=66) BCA32ABAF10344BBC3E00EFCD9DC77B9 { "code": "AltLeft", "key": "Alt", "modifiers": 0, "text": "", "type": "keyUp", "unmodifiedText": "", "windowsVirtualKeyCode": 18 } [1606145148.094][DEBUG]: DevTools WebSocket Command: Input.dispatchKeyEvent (id=67) BCA32ABAF10344BBC3E00EFCD9DC77B9 { "code": "ControlLeft", "key": "Control", "modifiers": 0, "text": "", "type": "keyUp", "unmodifiedText": "", "windowsVirtualKeyCode": 17 } For me it seems it tries to write the @ sign with sending 17, 18 down, then v, finally 17, 18 up. Which is Alt + Ctrl + v I assume, and that should be correct, that's how I write it on my hungarian keyboard. Nevertheless it is interpreted as simple Ctrl + V. Is there any other method I can use? Also, what shall I do if I want to overwrite the actual form element? Like in the example, I do not want to keep the text John there. Thank you in advance!
Danp2 Posted November 23, 2020 Author Posted November 23, 2020 (edited) @AttilaP Thanks for the concise reproducer. You could have coded the clipboard piece with ClipPut. 😉 Your code runs fine for me, so I think your diagnosis that this is a keyboard layout or language issue is on target. Edit: Read this -- https://chromedriver.chromium.org/help/keyboard-support Edited November 23, 2020 by Danp2 Latest Webdriver UDF Release Webdriver Wiki FAQs
AttilaP Posted November 23, 2020 Posted November 23, 2020 Thanks Danp2, I installed the US language pack which solved the problem. Now I face an another one: I try to download a file from a URL which is not a direct link to the file. I tried to use _WD_DownloadFile but that saved the HTML source instead. When I check the request in the browser, I see that the response header has this: content-disposition: attachment;filename="=?ISO-8859-1?Q?=D6n=E9letrajz.pdf?=" content-length: 36855 content-type: application/pdf;charset=UTF-8 And the file is downloaded. I can not find a link to mimic this behavior, unfortunately. Is there any way to grab these files and save them into a specific folder? I found this, but could not get it working. Related part (Python source): def enable_download_headless(browser,download_dir): browser.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command') params = {'cmd':'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_dir}} browser.execute("send_command", params)
Danp2 Posted November 23, 2020 Author Posted November 23, 2020 @AttilaP I don't know how to solve this for you, but if I come up with any ideas I'll let you know. A couple of questions -- Are you running in headless mode? Did you notice where they added some prefs related to downloads to their Chrome Options? Latest Webdriver UDF Release Webdriver Wiki FAQs
Danp2 Posted November 24, 2020 Author Posted November 24, 2020 @AttilaP I wonder if @TheDcoder's _WD_ExecuteCdpCommand function is what you need here. Latest Webdriver UDF Release Webdriver Wiki FAQs
Recommended Posts