Using remote debugging and download prefs #159
Replies: 4 comments 4 replies
-
Hi @code4dough2000, Yes, you can read up on how to use the WebCapabilities object in the following links, as well as looking at the examples in the test_Capabilities and test_FileUpDownload modules. https://github.com/GCuser99/SeleniumVBA/wiki#working-with-capabilities Hope that helps, Mike |
Beta Was this translation helpful? Give feedback.
-
Ok, try this where we set the download folder using CDP (in the background): Sub test_remoteDebugger()
'This test demonstrates how to connect to an existing Edge\Chrome browser instance and automate tasks.
'An example usage case - you need to manually login to a website first and then run some automation tasks.
'The pre-existing browser instance must be started on port 9222 for this to work.
'One way to launch the pre-existing browser is to create and run a shortcut on Desktop:
' "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 --user-data-dir="<path to temp user profile directory>"
'For more info, see https://github.com/GCuser99/SeleniumVBA/discussions/155
Dim driver As New WebDriver
Dim caps As WebCapabilities
'now we start automating the existing browser instance
driver.StartChrome
Set caps = driver.CreateCapabilities(initializeFromSettingsFile:=False)
'set debugger address to same port as browser
caps.SetDebuggerAddress "localhost:9222"
driver.OpenBrowser caps
driver.NavigateTo "https://www.selenium.dev/selenium/web/downloads/download.html"
driver.Wait 500
driver.SetDownloadFolder "%USERPROFILE%\Downloads" 'for Edge and Chrome only - no need to set in capabilities
driver.DeleteFiles "%USERPROFILE%\Downloads\file_1.txt", "%USERPROFILE%\Downloads\file_2.jpg"
driver.FindElementByCssSelector("#file-1").Click
driver.WaitForDownload "%USERPROFILE%\Downloads\file_1.txt"
driver.FindElementByCssSelector("#file-2").Click
driver.WaitForDownload "%USERPROFILE%\Downloads\file_2.jpg"
driver.CloseBrowser
driver.Shutdown
End Sub |
Beta Was this translation helpful? Give feedback.
-
"driver.SetDownloadFolder ~" downloads to the specified folder on port 9222 |
Beta Was this translation helpful? Give feedback.
-
I have some code for the preferences for Firefox and Chrome
However, from the discussion I learned I probably have to get familiar with CDP :-) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
If we look at the answer here: https://stackoverflow.com/questions/63091842/cannot-parse-capability-googchromeoptions-from-invalid-argument-unrecognized where it shows passing 2 different option objects to the constructor to get both remote debugging and setting the download folder with prefs - is there a way to do this?
Beta Was this translation helpful? Give feedback.
All reactions