Danp2 Posted December 11, 2020 Author Posted December 11, 2020 @CYCho Maybe this will help you identify the root cause -- https://www.reddit.com/r/MicrosoftEdge/comments/gx0h13/get_rid_of_sync_popup_at_start_of_using_edge_at/ Latest Webdriver UDF Release Webdriver Wiki FAQs
abodilsen Posted December 11, 2020 Posted December 11, 2020 2 hours ago, Danp2 said: @abodilsen Have you tried using _WD_Alert to see if it detects this popup? Hi Dan. Thank you for quickly replying. I have tried to add a _WD_Alert($sSession, 'accept') But I get the following result. _WD_Alert: {"value":{"error":"no such alert","message":"no such alert\n (Session info: chrome=87.0.4280.88)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0106C0C3+3326147]\n\tOrdinal0 [0x00F50851+2164817]\n\tOrdinal0 [0x00DD7140+618816]\n\tOrdinal0 [0x00DD1AB9+596665]\n\tOrdinal0 [0x00D43871+14449]\n\tOrdinal0 [0x00D71A5C+203356]\n\tOrdinal0 [0x00D4344E+13390]\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_Alert ==> Webdriver Exception: {"value":{"error":"no such alert","message":"no such alert\n (Session info: chrome=87.0.4280.88)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0106C0C3+3326147]\n\tOrdinal0 [0x00F50851+2164817]\n\tOrdinal0 [0x00DD7140+618816]\n\tOrdinal0 [0x00DD1AB9+596665]\n\tOrdinal0 [0x00D43871+14449]\n\tOrdinal0 [0x00D71A5C+203356]\n\tOrdinal0 [0x00D4344E+13390]\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"}}
Danp2 Posted December 11, 2020 Author Posted December 11, 2020 @abodilsen Ok... in your initial post, you used this xpath -- "//select[@name='agree']". Shouldn't that be "//button[@name='agree']"? Latest Webdriver UDF Release Webdriver Wiki FAQs
abodilsen Posted December 11, 2020 Posted December 11, 2020 Thank you Dan - it worked I see that I do not really understand the way xpath works. Do you have some literature on the topic that I can look into ?
Danp2 Posted December 11, 2020 Author Posted December 11, 2020 @abodilsen Lots of resources available on the net. Also, get the Chropath extension which can help with determining the correct xpath. Latest Webdriver UDF Release Webdriver Wiki FAQs
stamyuka Posted December 11, 2020 Posted December 11, 2020 Hi @Danp2, I am new to AutoIt and have been working on Chrome automation and have read lots of your extremely helpful posts. 😀 Recently I came across an issue that multiple instances of chromedriver can't be launched. Our use case is multiple users launching RemoteApp session to a server, which launches the AutoIt script on the server, and the script will launch chromedriver to start web page automation in Chrome for each of the user. However, the problem is everytime a new user launches RemoteApp session to the script, the new chromedriver launched will terminate the existing chromedriver for the sessions of previous user, thus interrupting all the automations for the previous user. I searched the forum and found similar issues posted by others and I saw you mentioned adding the following line at the beginning of the script to prevent the automatic closure of an existng webdriver console. I tried this but it's not working, new session launched still terminates the existing chromedriver in the previous user's RemoteApp session. I would like to seek for you advice is there any other workaround can resolve this problem so that multiple users can remotely connect and launch chromedriver within their own sessions without disrupting each other? Thank you so much for your help in advance. Looking forward for your reply. _WD_Option('DriverClose', False)
Danp2 Posted December 12, 2020 Author Posted December 12, 2020 Hi @stamyuka You will need to provide a more detailed explanation before I can offer any suggestions. Post your code that shows the options you are setting before calling _WD_Startup. Each chromedriver instance would need to use a different port. How are you dealing with that? Have you considered using a single instance of chromedriver to handle multiple user sessions? If you ruled this out, please explain why. FWIW, when I run the following code repeatedly, only the initial run launches an instance of chromedriver and it is reused on subsequent runs -- #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "http://finance.yahoo.com") Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') _WD_Option('DriverClose', False) $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}' EndFunc Latest Webdriver UDF Release Webdriver Wiki FAQs
stamyuka Posted December 12, 2020 Posted December 12, 2020 (edited) Thank you so much @Danp2 for the reply. Please see below the relevant portion of the source code for the chrome start up, I am following the standard approaches I have seen in this forum and the demo. I removed the other irrelevant portion of the codes such as my automation tasks to make it shorter. Basically we need to keep the script running to keep listening for new user events and execute tasks until user closes the browser. I have tried change to different port (other than 9515), such as _WD_Option('Port', 9516), perhaps I am doing it the wrong way? In addition, regarding using a single instance of chromedriver to handle multiple user sessions, I am not sure if it's possible in our case. Because the script runs on a server, users need to connect to run it as RemoteApp. Therefore, inside each remote session I guess it's supposed to initiate individual chromedriver and then launch Chrome from it. I'm not sure if it's possible to have one single chromedriver instance running in the background in this case? The issue we are facing is whenever a second user goes into it, it terminates the first user's chromedriver instance, therefore the automation process for the first user is terminated as well. Thank you again for your kind help on this. expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" #include <GuiComboBoxEx.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> Call(SetupChrome) _WD_Startup() If @error <> $_WD_ERROR_Success Then Exit -1 EndIf $sSession = _WD_CreateSession($sDesiredCapabilities) ; ------ define all variables ------- _WD_Window($sSession, "maximize") _WD_Navigate($sSession, "https://www.samplepage.com") Opt("WinTitleMatchMode", 2) while 1 ; ----- Keep monitoring user events and execute automation tasks, do nothing if no event ------ Sleep(1000) If Not WinExists("Google Chrome") Then ExitLoop EndIf WEnd _WD_DeleteSession($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverClose', False) $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' EndFunc Edited December 13, 2020 by stamyuka
stamyuka Posted December 12, 2020 Posted December 12, 2020 Sorry for another post @Danp2 , I just tried further and would like to provide an update (I don't have the permission to modify my existing post yet 😥). I fully compared the code you pasted for launching Chrome driver, and after comparison I added the extra capabilities, and remove _WD_Shutdown() at the end of my script. I ran below code, but when run it 2nd time, it still terminates the chromedriver in the 1st run, which will break the functions inside the loop and below error occurs (I believe it's because chrome driver ended in the 1st script run so that the window interaction won't work in the 1st script run). Not sure if there's anything I missed or did incorrectly? I tried to run script 2 times in one same Windows desktop session, also tried to run script 2 times separately in two different RemoteApp sessions. Both of these testing failed and 2nd script terminated the chromedriver in 1st script. expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" #include <GuiComboBoxEx.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() If @error <> $_WD_ERROR_Success Then Exit -1 EndIf $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Window($sSession, "maximize") Opt("WinTitleMatchMode", 2) Local $tabHash = ObjCreate('System.Collections.Hashtable') Local $firstTab = True While 1 $aHandles = _WD_Window($sSession, 'handles') For $sHandle In $aHandles If Not $tabHash.ContainsKey($sHandle) Then _WD_Window($sSession, 'Switch', '{"handle":"' & $sHandle & '"}') $tabHash.Add($sHandle, 1) MsgBox($MB_OK, 'New Tab Detected', 'Click OK to open webpage.') _WD_Navigate($sSession, "https://www.google.com") ExitLoop EndIf Next Sleep(1000) If Not WinExists("Google Chrome") Then ExitLoop EndIf WEnd Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') _WD_Option('DriverClose', False) $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}' EndFunc
CYCho Posted December 12, 2020 Posted December 12, 2020 (edited) @stamyuka Have you tried keeping a chromedriver.exe file in each user's local computer and make reference to that local file in SetupChrome() function? _WD_Option('Driver', @DocumentsCommonDir & '\chromedriver.exe') Edited December 12, 2020 by CYCho zPlayer - A Small Audio and Video Player
Danp2 Posted December 12, 2020 Author Posted December 12, 2020 (edited) 12 hours ago, stamyuka said: I have tried change to different port (other than 9515), such as _WD_Option('Port', 9516), perhaps I am doing it the wrong way? That command tells the UDF which port to use when communicating with the webdriver. You also need to tell the webdriver to use this alternate port. For chromedriver, it would look something like this -- Local $iAltPort = 9516 _WD_Option('Port', $iAltPort) _WD_Option('DriverParams', '--verbose --port=' & $iAltPort & ' --log-path="' & @ScriptDir & '\chrome.log"') If you try to launch a 2nd instance of chromedriver without changing the port number, it will immediately exit after displaying this error message in the console -- [1607779217.305][SEVERE]: bind() returned an error: Only one usage of each socket address (protocol/network address/port) is normally permitted. (0x2740) IPv6 port not available. Exiting... 12 hours ago, stamyuka said: The issue we are facing is whenever a second user goes into it, it terminates the first user's chromedriver instance, therefore the automation process for the first user is terminated as well. Make sure that you are running the latest release of the UDF. Then try adding some logging to try to determine why the chromedriver instance is being terminated. Edited December 12, 2020 by Danp2 Fixed quote issue SkysLastChance 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
Nine Posted December 12, 2020 Posted December 12, 2020 If I use quotes around port it is not working for me. This is what I use : Local $iAltPort = 9516 _WD_Option('Port', $iAltPort) _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log" --port=' & $iAltPort) “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
Danp2 Posted December 12, 2020 Author Posted December 12, 2020 @Nine Thanks for catching my mistake. I went back and edited the post to use a single quote instead of a double quote. 🙄 Latest Webdriver UDF Release Webdriver Wiki FAQs
stamyuka Posted December 12, 2020 Posted December 12, 2020 Thanks a lot for the suggestion. I tried below two solutions based on the suggestions, and #1 works for me 😁 1. Use the alternative port solution, I added functions to check if the port has been taken by any process at the beginning of my script. If it's taken, add 1 to the port number and keep trying until it finds an available port and then use that to launch chrome driver (start trying from 9515). Using this solution, chrome driver can be launched separately for each user in each remote session. I attached the updated code below and it's working for me, thanks everyone for your help! 2. Use one shared chromedriver instance for multiple user's chrome sessions (This is not working for me in RemoteApp scenario). I updated the UDF to the latest version, and tried to launch scripts multiple times in separated remote sessions. But the problem is, when 2nd user launches remote session, it detects chrome driver process already exists, and then the Chrome browser is launched in the 1st user's remote session. As a consequence, 1st user sees two chrome browser window while the 2nd user sees nothing. expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" #include <Array.au3> #include <ConnView.au3> #include <GuiComboBoxEx.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> Local $sDesiredCapabilities, $sSession, $aArray, $_Port, $aHandles Local $iAltPort = 9515 While 1 $aArray = _CV_GetExtendedTcpTable() $_Port = _ArrayFindAll($aArray, $iAltPort, 0, 0, 0, 0, 2) If @error Then ExitLoop Else $iAltPort = $iAltPort + 1 EndIf WEnd SetupChrome($iAltPort) MsgBox($MB_OK, 'Message', 'Click OK to start Chrome Driver at local port: ' & $iAltPort) _WD_Startup() If @error <> $_WD_ERROR_Success Then Exit -1 EndIf $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Window($sSession, "maximize") Opt("WinTitleMatchMode", 2) Local $tabHash = ObjCreate('System.Collections.Hashtable') Local $firstTab = True While 1 $aHandles = _WD_Window($sSession, 'handles') For $sHandle In $aHandles If Not $tabHash.ContainsKey($sHandle) Then _WD_Window($sSession, 'Switch', '{"handle":"' & $sHandle & '"}') $tabHash.Add($sHandle, 1) MsgBox($MB_OK, 'New Tab Detected', 'Click OK to open webpage.') _WD_Navigate($sSession, "https://www.google.com") ExitLoop EndIf Next Sleep(1000) If Not WinExists("Google Chrome") Then ExitLoop EndIf WEnd _WD_DeleteSession($sSession) _WD_Shutdown() Func SetupChrome($iAltPort) _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', $iAltPort) _WD_Option('DriverParams', '--verbose --port=' & $iAltPort & ' --log-path="' & @ScriptDir & '\chrome.log"') _WD_Option('DriverClose', False) _WD_Option('DriverDetect', False) ;$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}' EndFunc SkysLastChance 1
Danp2 Posted December 12, 2020 Author Posted December 12, 2020 @stamyuka Glad you found a workable configuration. FWIW, you could probably move this line before your While loop -- $aArray = _CV_GetExtendedTcpTable() Latest Webdriver UDF Release Webdriver Wiki FAQs
stamyuka Posted December 13, 2020 Posted December 13, 2020 Thank you @Danp2. 😃 I also noticed those extra chromeOptions assigned to $sDesiredCapabilities in your suggested code let Chrome no longer display the message: Chrome is being controlled by automated test software. Many thanks for all your help !! $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}'
cdeb Posted December 13, 2020 Posted December 13, 2020 (edited) WebDriver UDF just doesn't want to work.... First error: "C:\Users\...\wd_core.au3" (173) : ==> Variable used without being declared...: Global $_WD_BFORMAT = $SB_UTF8 Global $_WD_BFORMAT = ^ ERROR I solved it with Global $_WD_BFORMAT = 4; in wd_core.au3 Second error: If I try this script expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $sDesiredCapabilities, $sSession ;SetupEdge() ;SetupChrome() SetupGecko() _WD_Startup() If @error <> $_WD_ERROR_Success Then Exit -1 EndIf $sSession = _WD_CreateSession($sDesiredCapabilities) If @error = $_WD_ERROR_Success Then ConsoleWrite("@error: " & @error & @CRLF) EndIf MsgBox($MB_ICONINFORMATION, "Demo complete!", "Click ok to shutdown the browser and console") ;~ _WD_Navigate($sSession, "https://www.google.com/") _WD_DeleteSession($sSession) _WD_Shutdown() Func SetupGecko() _WD_Option('Driver', 'geckodriver.exe') _WD_Option('DriverParams', '--log trace') _WD_Option('Port', 4444) $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}' 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 }}}}' EndFunc Func SetupEdge() _WD_Option('Driver', 'msedgedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"binary": "' & StringReplace (@ProgramFilesDir, "\", "/") & '/Microsoft/Edge/Application/msedge.exe", "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false}}}}' EndFunc I get the following error. _WD_IsLatestRelease: True _WD_IsLatestRelease ==> Success _WDStartup: OS: WIN_81 WIN32_NT 9600 _WDStartup: AutoIt: 3.3.12.0 _WDStartup: WD.au3: 0.3.1.0 (Up to date) _WDStartup: WinHTTP: 1.6.4.2 _WDStartup: Driver: geckodriver.exe _WDStartup: Params: --log trace _WDStartup: Port: 4444 __WD_Post: URL=HTTP://127.0.0.1:4444/session; $sData={"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}} "C:\Users\....\wd_core.au3" (1633) : ==> Variable used without being declared.: If (Not IsObj($vResult)) Or ObjName($vResult, $OBJ_STRING) <> 'Scripting.Dictionary' Then Return If (Not IsObj($vResult)) Or ObjName($vResult, ^ ERROR Can anyone help me understand why this is not working? Edited December 13, 2020 by cdeb
Nine Posted December 13, 2020 Posted December 13, 2020 38 minutes ago, cdeb said: $SB_UTF8 Is in StringConstants.au3 (include folder). 41 minutes ago, cdeb said: $OBJ_STRING is in AutoItConstants.au3 (include folder). “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
Danp2 Posted December 13, 2020 Author Posted December 13, 2020 2 hours ago, cdeb said: AutoIt: 3.3.12.0 That version was released 6 years ago. Please upgrade to a more recent version (such as 3.3.14.5, which is what I've been testing with) and then let us know if you continue to encounter problems. Latest Webdriver UDF Release Webdriver Wiki FAQs
cdeb Posted December 14, 2020 Posted December 14, 2020 I have updated to the latest version of autoit and it works correctly, thank you Danp2 1
Recommended Posts