Issue in launching Chrome via Selenium VBA - vba

I have tried to launch Chrome browser via Selenium VBA by using the below code. I am getting this error when executing the code "WebRequestError
The underlying connection was closed: An unexpected error occurred on a receive." But IE browser is working fine.
Sub samp()
Dim drv As New Selenium.WebDriver
drv.Start "Chrome"
drv.Get "www.google.com"
End Sub

I fixed this by installing the latest ChromeDriver, and replacing the .exe-file with the file located in my AppData.
Requirements
Download and install SeleniumBasic VBA, and set the reference in VBA editor (https://florentbr.github.io/SeleniumBasic/)
Steps
Download latest WebDriver from: https://sites.google.com/a/chromium.org/chromedriver/downloads
Open folder C:\Users\ Username\AppData\Local\SeleniumBasic
Replace chromedriver.exe with existing file
Example
Now this example code below works as intended
Sub driver()
Dim selenium As New selenium.WebDriver
selenium.Start "chrome", "http://google.com"
selenium.Get "/"
End Sub

Related

OpenQA cant detect my chromedriver webdriver

can someone tell me why i keep getting an error while running this:
IWebDriver driver = new ChromeDriver("#C:/Users/xxx/xxx/xxx xxx/xxx/chromedriver");
the error said that the file "chromedriver.exe" doesnt exist but it is in that folder. I downloaded the chromedriver file again through the link that the error gave me. still doesn't work.

Loading Edge 83 with Selenium, in EdgeHTML mode (UseChromium = false). Returns Error

I'm trying to launch Edge using the EdgeHTML renderer mode, within Selenium, using Visual Studio C#.. I'm using the version 83.0.478.58 (64bit) and the driver 83.0.478.58 (64bit). Installed via nuget.
If I launch the browser using it works fine...
EdgeOptions options = new EdgeOptions();
options.UseChromium = true;
options.AddUserProfilePreference("download.default_directory", #"C:\temp\");
EdgeDriver edgeDriver = new EdgeDriver(options);
By default UseChromium is False, which should launch the browser in the EdgeHTML renderer. If I use the below code it will error out.
EdgeOptions options = new EdgeOptions();
options.AddUserProfilePreference("download.default_directory", #"C:\temp\");
EdgeDriver edgeDriver = new EdgeDriver(options);
The browser will open a new instance, but once the browser is open. The code bugs out and returns the error message,
OpenQA.Selenium.WebDriverException: 'The new session command returned a value ('Unknown error') that is not a valid JSON object.'
If I just try and simply initialise without the options, I still get the same error.
Anyone got any ideas? Looking around I see documentation and guides all over that launch the browser without UseChromium.
Cheers
Looks like you are trying to set the default download directory for the MS Edge legacy (EdgeHTML) browser using the Selenium code.
I want to inform you that it is possible to set the default download directory for the MS Edge (Chromium) browser as you had already tried that successfully but it is not possible to set the default download directory for the MS Edge legacy (EdgeHTML) browser using the Selenium code.
As a workaround, you can try to set the download directory manually.
References:
Change the default file download path for Edge using selenium
Change default download location in Edge

Selenium code not executed after driver.get (browser is IE)

I am new to selenium. My code works fine with Chrome webdrive. However, when I switch to IE webdrive, my code does not execute after drive.get.
from selenium import webdriver
driver = webdriver.Ie(executable_path=r"C:\Drivers\IE_Driver\IEDriverServer.exe")
driver.get("https://www.amazon.com")
print(driver.current_url)
print ("Test")
I have verified your code & its working without any issue.
from selenium import webdriver
driver = webdriver.Ie(executable_path=r"C:\IEDriverServer.exe")
driver.get("https://www.amazon.com")
print(driver.current_url)
print ("Test")
Output:
I would suggest to Download IE Drivers based on your OS (Windows 32 or 64 bit) and then try once again
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
you have to do the prerequisite steps mentioned there , expecially disabling the enhanced protection. I was able to reproduce your issue.
uncheck the box for everything internet,local , trustred and restricted
I have tried set webdriver.IeOptions ignore_protected_mode_settings = True, then drive.get response.

CanĀ“t use selenium on vba

I'm used to running a script on vba using selenium in windows 7 with no problem, and since I installed Windows 10 a just can not open the Google Chrome automated window.
Already installed google chromedriver and the selenium library
Put the C:\....\AppData\Local\SeleniumBasic on the environmental path
The Google Chrome is version 78.0.3904.108 and the chromedriver 78.0.3904.105, and people don't seem to have problems with that...
This is the start of the code, where crashes...
Dim bot As New Selenium.ChromeDriver, posts As WebElements, post As WebElement, i As Integer,
mysheet As Worksheet, keys As Selenium.keys
bot.Start "chrome", "https://valor.globo.com/impresso" **'it gots the error right here**
bot.Get "/"
Anyone having this problem, knows what to do?
Check your version of Chrome, then download the ChromeDriver for your version.
This code should open Google.
The browser will close as soon as the Sub ends, so either declare the ChromeDriver on a global variable, or don't let the Sub end.
Option Explicit
Dim MyChromeDriver As ChromeDriver
sub MyCD
Set MyChromeDriver = New ChromeDriver
MyChromeDriver.Get "https://www.google.com/"
End Sub

How do I set Chrome download directory with Selenium & VBA

Using Win7, Office2010, Chrome 58, and Selenium 2.0.9, I'm automating the downloading of a number of files from a few websites (NB, I actually need the files and the sites are not mine - I'm not testing my own site), and I'd like to control where the files end up being downloaded.
I have looked at quite a number of search results and everything I've found has led me to the following versions of code, each Driver.SetPreference variation has been tested independently and none of them work.
Private Sub DownloadDirTest()
Dim Driver As Selenium.ChromeDriver
Set Driver = New Selenium.ChromeDriver
Driver.SetPreference "browser.download.dir", "\\server\share\my\long\path"
Driver.SetPreference "browser.download.dir", "\\\\server\\share\\my\\long\path"
'after mapping Y: to "\\server\share\my\long\path" in Windows Explorer
Driver.SetPreference "browser.default_directory", "Y:\"
Driver.SetPreference "browser.download.dir", "c:\"
Driver.SetPreference "browser.default_directory", "c:\"
Driver.Start "Chrome", "http://google.com"
Driver.Close
End Sub
As can been seen here:
Most of the references I've seen are for Python, Java or Ruby, and they all make reference to something like:
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
There doesn't seem to be any equivalent ChromeOptions available to VBA.
1) Does anyone know the actual property name to correctly set the download directory?
2) I'm not particularly wedded to Chrome, though it seems to be faster than IEDriver (in my initial testing), and I can't get the current Firefox driver to work. If someone has pointers to how to reliably set the DL directory in either of the other browsers (and a link to an updated Firefox driver - I haven't been able to find it via half-hearted searching), I'm open to using those.
The preferences from your example are specific to Firefox. You need to set the ones specific to Chrome to change the download directory:
Dim driver As New ChromeDriver
driver.SetPreference "download.default_directory", "c:\temp"
driver.SetPreference "download.directory_upgrade", True
driver.SetPreference "download.prompt_for_download", False
driver.SetPreference "safebrowsing.enabled", True
driver.SetPreference "plugins.plugins_disabled", Array("Chrome PDF Viewer")
driver.Get "http://google.com"
driver.Quit