Can´t use selenium on vba - 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

Related

getAttribute("value") doesn't work with driver 91.0.4472.19 and Chrome 91.0.4472.77

After Chrome and driver update to 91th version I found the VBA macro with driver 91.0.4472.19 (win32) become return empty string ("") from input tag 'value' attribute:
Dim ch As SeleniumWrapper.WebDriver
Dim el As WebElement
' some code here ...
ch.findElementById("htmlLoginId").SendKeys login
Set el = ch.findElementById("htmlLoginId")
txt = el.getAttribute("value")
With older driver version 90.0.4430.24 this works fine. Hope it will be fixed in next driver versions.
Is there another way to get value from input[type=text] tag? I want to avoid situation if this bug will not be fixed in 92th version and 90th driver version become incompatible.
We have been fighting with this issue a couple of days since the new chrome driver came out. A workaround we did was to bypass calls to the webdriver's getAttribute method if we want to retrieve properties (that are not html attributes) of the element and instead use the following custom script:
browser.executeScript(`return arguments[0].${this.textAttribute}`, el);
The above example is valid for protractor, which is what we are using. If your stack is different, you need to call the appropriate alternative to browser.executeScript, but the script itself would be quite the same.
We did it!
ARG CHROME_VERSION="90.0.4430.212-1"
RUN wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb \
&& apt install -y /tmp/chrome.deb \
&& rm /tmp/chrome.deb
./webdriver-manager update --versions.chrome 90.0.4430.24
This was a regression in chrome driver 91. A fix has been made. Hopefully an updated v91 chrome driver will be released soon.
https://bugs.chromium.org/p/chromium/issues/detail?id=1205107
In the meantime we are using chrome driver 90.
I am reproducing this doing getAttribute('innerHTML') as well. As another workaround, run tests with Firefox instead of Chrome
We are also facing the similar issue while getting attribute data of an element using GetAttribute() of web element in C#. Struggled two days to find out what the root cause is. And for us it is not possible to make workarounds as code base is already frozen. Waiting for the fix. And as per the issue https://bugs.chromium.org/p/chromium/issues/detail?id=1205107 it may take couple of weeks to release another version with fix.
The issue has been fixed with the new release of ChromeDriver 91.0.4472.101 and ChromeDriver 92.0.4515.43

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.

Selenium - Edge - How to start a webdriver session with work profile?

My application does not have a login page to get authenticated. It uses my organizational email id (SSO) to authenticate my access to the application. I am using Version 80.0.361.66 (Official build) (64-bit) of Microsoft Edge.
driver = webdriver.Edge()
driver.maximize_window()
selenium version - selenium==3.141.0
This edge session does not use my work profile . It opens a new session because of which my work profile is not loaded and my access to the application is denied. However, I did try to update the version of selenium to use EdgeOptions. But, that didn't work as well. Below is the code :
options = webdriver.EdgeOptions()
options.add_argument("user-data-dir=C:\\Users\\Ajmal.Moideen\\AppData\\Local\\Microsoft\\Edge\\User Data")
driver = webdriver.Edge(options=options)
driver.maximize_window()
selenium version=4.0.0a3
Here's how I got it to work - I am using Chromium Edge 85.0.564.51 with Selenium 3.141.0.
Selenium 3.141.0 from pip doesn't seem to support new Chromium-based Edge Webdriver, but Microsoft supplies it in their msedge-selenium-tools package (better documentation here) as mentioned by Matthias' comment on your question.
First, grab the Chromium Edge webdriver here - get the version that matches your version of Edge (go to chrome:version in Edge to see what version you are running). Put the webdriver somewhere convenient, you need to set driverpath below to point to it.
Install the pip packages:
pip install msedge-selenium-tools selenium==3.141
In your code, import the msedge-selenium-tools Webdriver and Options modules and build the webdriver as shown:
from msedge.selenium_tools import Edge, EdgeOptions
...
options = EdgeOptions()
options.use_chromium = True
options.add_argument("--user-data-dir=C:\\Users\\YOUR-USERNAME\\AppData\\Local\\Microsoft\\Edge\\User Data")
options.add_argument("--start-maximized")
driverpath = 'msedgedriver.exe'
driver = Edge(driverpath, options=options)
Voilà, that should do the trick.
P.S.: Even though chrome:version will show your Profile path with a trailing \Default, don't include that in your --user-data-dir argument above, since the driver seems to append \Default to the end.

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

Issue in launching Chrome via Selenium 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