seadoggie01 Posted August 10, 2020 Share Posted August 10, 2020 Sorry to keep hijacking your thread, but how? I've only done this with Run($sCmd, "", Default, $STDOUT_CHILD) before All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Nine Posted August 10, 2020 Share Posted August 10, 2020 (edited) Compile your WebDriver script and use this one for grabbing the console : #include <Constants.au3> $pid = Run ("Test.exe", "", @SW_SHOW, $STDERR_MERGED) ProcessWaitClose ($pid) $sText = StdoutRead ($pid) MsgBox ($MB_SYSTEMMODAL,"",$sText) Works for me. Edited August 10, 2020 by Nine Danp2 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 Link to comment Share on other sites More sharing options...
Danp2 Posted August 10, 2020 Author Share Posted August 10, 2020 This thread might give you some ideas as well -- Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Jemboy Posted August 12, 2020 Share Posted August 12, 2020 I have been reworking a Internet Explorer automation to use Chrome. Sofar I have been working 2 days to finally start understanding how to get Webdriver UDF to work. Basically I use the script to log into the website, so the user does not have to do it and also I do not have to provide everyone with the password everytime. Using the the Webdriver UDF, I noticed the following Dos box everytime I run the script.Could the chromedriver,exe be run silently, to make the automation less intrusive to my users ? After some hours the website, times outm so the script has to logon again. In my original IE script, I solved this the following way: Check if the one of the IE instances of the websote was "active" Refresh the website, if the URL changed to the login page, close the session and do a complete new login With the webdriver UDF, I dont know how to check if an instance of the website is opened. SO does anyone know how I could (with webdriver UDF): check if any chrome instance or tab has the page opended focus on that page refresh the page (I could then check the URL with _WD_Action($sSession, 'url') if page needs login, then close the chrome instance or tab reopen the page and login or just get the focus to the instance/tab so the user can use this Any hints how to proceed would be very helpful. TIA. Link to comment Share on other sites More sharing options...
Danp2 Posted August 12, 2020 Author Share Posted August 12, 2020 2 minutes ago, Jemboy said: Could the chromedriver,exe be run silently, to make the automation less intrusive to my users ? Yes. This is covered in the Wiki FAQ section Quote With the webdriver UDF, I dont know how to check if an instance of the website is opened. Take a look at _WD_Attach, a function found in wd_helper.au3 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Jemboy Posted August 13, 2020 Share Posted August 13, 2020 @Danp2 I have just looked at the FAQ, however chromedriver is only found 5 times in the FAQ with nothing pointing to how to run the chromedriver silently. The word "silent" does not even appear in the FAQ. CORRECTION: Just found " How to hide the webdriver console" in the FAQ. May be adding some keywords like DOSbox, silent, surpreess would make it easier to find this 😁 About _WD_Attach, I think I could work with that, by: try to attach to an URL or Title and check if there is a match no match: open new page match: refresh and check if user is still logged into the page, if not, do a re-login of the user Have not tested the above yet, but will check how this tonight and tommorow. Thanks for your input! Link to comment Share on other sites More sharing options...
Jemboy Posted August 14, 2020 Share Posted August 14, 2020 When I open a Chrome page manually and then create a session with autoit and do a _WD_Attach it will fail. Also the moment I do an _WD_Shutdown, the Chrome session I created is gone, so it seems I must just exit the autoitscript without any cleanup. When the autoit script exits and I try again, sometimes running the script again won't work, also sometimes an chrome.exe DOS box keeps popping up every x minutes.... I have to do more testing to find out why things are behaving like I this.... My overall thoughts are: nice to have an univeral way to automate webbrowsers, however the way it has been put together is definitely not easy! 😁 Link to comment Share on other sites More sharing options...
Danp2 Posted August 14, 2020 Author Share Posted August 14, 2020 2 hours ago, Jemboy said: When I open a Chrome page manually and then create a session with autoit and do a _WD_Attach it will fail. IIRC, you can't use Webdriver to attach to a previously open instance of Chrome. Therefore, it makes sense to me that it doesn't work as posted. If I've misunderstood, please post a short script that demonstrates the issue. Quote Also the moment I do an _WD_Shutdown, the Chrome session I created is gone, so it seems I must just exit the autoitscript without any cleanup. Not sure that I follow. Are you calling _WD_DeleteSession first? Show us your code so that we can see what you are attempting to do. Quote When the autoit script exits and I try again, sometimes running the script again won't work, also sometimes an chrome.exe DOS box keeps popping up every x minutes.... "Won't work" doesn't give us enough details to understand the issue. Show us the results from the Scite console for a failed attempt to run, FWIW, I do most of my testing with Firefox, but I do recall seeing the situation where the DOS box keeps reappearing with Chrome. More testing will need to be done to determine if this is due to something with this UDF. Quote My overall thoughts are: nice to have an univeral way to automate webbrowsers, however the way it has been put together is definitely not easy! 😁 Imagine how difficult it would be if this UDF library didn't exist. 😜 On a more serious note, I appreciate the feedback and I'm open to suggestions which would help improve the UDF. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Jemboy Posted August 14, 2020 Share Posted August 14, 2020 At the moment I kill chromedrive.exe before starting using _SetupChrome and _WD_Start. I also do this afterwards to leave the created Chrome windows enabled. Running my scriptt a second time without killing chromedriver.exe, will let my script fail due to chromedrive.exe running. For now this is OK with me. Does anyone know how to disable the chromedriver.exe to create a logfile? I have removed --verbose, added --silent to the _WD_Option('DriverParams',... but to no avail. Link to comment Share on other sites More sharing options...
Danp2 Posted August 14, 2020 Author Share Posted August 14, 2020 @Jemboy Show us your code if you want further assistance. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
hemal Posted August 14, 2020 Share Posted August 14, 2020 Need expert advice here. I am not able to select value from drop down. Am I missing something? Local Const $CTRL_INPUT_list = "//select[@id='servicelink']" $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $CTRL_INPUT_list) $sRet = _WD_ElementAction($sSession, $sElement, "My Fav option") Link to comment Share on other sites More sharing options...
Danp2 Posted August 14, 2020 Author Share Posted August 14, 2020 Take a look at _WD_ElementOptionSelect. Pretty sure you can find a working example on the forum. hemal 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
hemal Posted August 15, 2020 Share Posted August 15, 2020 Thank you @Danp2 for solving my previous issue. #include "wd_core.au3" #include "wd_helper.au3" #include "WinHttp.au3" Local $sDesiredCapabilities, $sSession, $sElement, $aElements, $sButton _WD_Attach($sSession, "Login to TradeLink" ) $sSession = _WD_CreateSession($sDesiredCapabilities) Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log trace --connect-existing') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized"]}}}}' EndFunc Need help with WD_Attach. Want to use and automate the existing chrome window but not able to. Thanks in advance ✋ Link to comment Share on other sites More sharing options...
Danp2 Posted August 15, 2020 Author Share Posted August 15, 2020 @hemal I can see several issues with your script as written -- Not a big deal, but you shouldn't need to include winhttp.au3 You can't call _WD_Attach before $sSession contains a valid session ID I don't believe that you can connect to an existing instance of Chrome, so your attempt to use "--connect-existing" will likely be ignored or will generate an error condition Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
hemal Posted August 16, 2020 Share Posted August 16, 2020 Hi @Danp2, I've tried your suggestions, but no luck. Can you please tag any working example to use existing Chrome instance? Thanks .. . Link to comment Share on other sites More sharing options...
Danp2 Posted August 16, 2020 Author Share Posted August 16, 2020 @hemal Please go back and reread my last response, particularly the first portion of the last bullet point. hemal 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Jemboy Posted August 17, 2020 Share Posted August 17, 2020 _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') The example I grabbed the forum used a function SetupChrome() with the above line, this resulted in logging webdriver data to chrome.log with every run. In my production enviroment, I wanted to disable this logging . Replacing just removing the path, so the webdriver won't know were to write the log file was enough. Other options likereplacing --verbose by --silent or , --disable-logging did not work. _WD_Option('DriverParams', '') Link to comment Share on other sites More sharing options...
Jemboy Posted August 17, 2020 Share Posted August 17, 2020 (edited) @Danp2The code below is an example script (using the webdriver for Chrome). This code will run everytime and also create a "Chrome" session everytime it is executed. Because the script automates the login for users (so the user does not have to login manually), I can not delete the session (_WD_DeleteSession($sSession) ) or do a (_WD_Shutdown() ). So I have to kill the chromedriver.exe at the end of the script. If I do not kill the chromedriver.exe the script will not run correctly a second time even if I kill the "chromedrive.exe" after the "bad" execute. expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" #include <Array.au3> $_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error Local $sDesiredCapabilities, $sSession, $sElement Local $sEmailAddress = 'admin@yourstore.com' Local $sPassword = 'admin' Global $sTitle = "NopCommerce Demo v1.0" ;Script needs chromedriver.exe, install if not present! If not FileExists (@ScriptDir & "\chromedriver.exe") then Beep (500,1000) $ResFI = FileInstall (".\chromedriver.exe",@ScriptDir & "\",$FC_NOOVERWRITE) If $ResFI=0 Then MsgBox (262144,$sTitle,"Error: Could not install Chromedriver.exe nodig!") Exit EndIf EndIf ; Check if Chromedriver.exe is active, and ask to kill ? Local $aProcessList = ProcessList("chromedriver.exe") If $aProcessList[0][0]>0 Then $CDMesaj = "Chromedriver.exe is still active." & @CRLF & "Do you want to close Chromedriver?" $Answ = MsgBox (262144 + $MB_YESNO,$sTitle,$CDMesaj) If $Answ = $IDYES Then KillChromeDriver () ; Kill Chromedriver Else MsgBox (262144,$sTitle,"You selecte 'No', so chromedriver.exe is still active!") Exit EndIf EndIf SetupChrome() $ResSU = _WD_Startup() $ResSUE = @error If $ResSU=0 then MsgBox (262144,$sTitle,"Result Startup = " & $ResSU & " " & "Error = " & $ResSUE) SplashTextOn($sTitle, "Starting NopCommerce autologin wrapper script." & @CRLF & @CRLF & "This will take several seconds...", -1, 250, -1, -1, $DLG_TEXTLEFT, "", 24) $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Window($sSession, 'maximize') ;maximize the webdriver "Chrome window" _WD_Navigate($sSession, "https://admin-demo.nopcommerce.com/login?") _WD_LoadWait($sSession) SplashOff() $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='Email']") _WD_ElementAction($sSession, $sElement, 'clear') _WD_ElementAction($sSession, $sElement, 'value', $sEmailAddress) _WD_LoadWait($sSession,1000) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='Password']") _WD_ElementAction($sSession, $sElement, 'clear') _WD_ElementAction($sSession, $sElement, 'value', $sPassword) _WD_LoadWait($sSession,1000) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='button-1 login-button']") _WD_ElementAction($sSession, $sElement, 'click') _WD_LoadWait($sSession,2000) $CurURL = _WD_Action($sSession, 'url') ;MsgBox (262144,$sTitle,"URL = " & $CurURL) If $CurURL <>"https://admin-demo.nopcommerce.com/admin/" Then MsgBox (262144,$sTitle,"NopCommerce demo login failed." & @CRLF & "Please try again!" & @CRLF & @CRLF & "if the problem persists, then contact your IT Wizard.!") KillChromeDriver () Exit EndIf ;_WD_DeleteSession($sSession) ;If @error Then Exit SetError(6, @error) ;_WD_Shutdown() KillChromeDriver () ; Kill Chromedriver Func KillChromeDriver() ; Kill Chromedriver.exe ;Exit Local $aProcessList = ProcessList("chromedriver.exe") For $i = 1 To $aProcessList[0][0] ProcessClose($aProcessList[$i][1]) Next EndFunc 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,"prefs": {"credentials_enable_service": false}}}}}' EndFunc Edited August 17, 2020 by Jemboy Link to comment Share on other sites More sharing options...
Danp2 Posted August 17, 2020 Author Share Posted August 17, 2020 3 hours ago, Jemboy said: _WD_Option('DriverParams', '') This line can be dropped all together since this option defaults to a blank string Quote I do not kill the chromedriver.exe the script will not run correctly a second time even if I kill the "chromedrive.exe" after the "bad" execute. Instead of killing chromedriver, you should try saving the session ID and then reusing it on subsequent runs of the script. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danp2 Posted August 19, 2020 Author Share Posted August 19, 2020 @hemal See if this works for you to reattach to an previous instance of Chrome -- #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sElement, $oJSON, $oCaps, $sDebugger SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "http://google.com") $oJSON = Json_Decode($_WD_SESSION_DETAILS) $oCaps = Json_Get($oJSON, "[value][capabilities]") $sDebugger = $oCaps.Item('goog:chromeOptions').Item('debuggerAddress') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"debuggerAddress": "' & $sDebugger & '"}}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "http://yahoo.com") 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 P.S. I know about the Chrome "console" window that pops up, but haven't had time to investigate further hemal 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Recommended Posts