I'm a beginner with both VBA and Selenium so forgive me if this is too obvious. I'm trying to see whether I can make VBA open a Chrome window to check that Selenium works fine, via the code below:
Option Explicit
Private MyBrowser As Selenium.ChromeDriver
Sub TestSelenium()
Set MyBrowser = New Selenium.ChromeDriver
MyBrowser.Start
End Sub
I, however, get the following error:
Does anyone know what I could be doing wrong?
Thanks so much
As it turns out I had to download Microsoft .NET 3.5 Framework for it to work
Related
I have a small Macro taking me a to a website on Chrome using a shell command, but I'm hoping to chain it to another that populates the username and password on the site. Is this possible? My code so far:
Sub Logintest2()
Dim chromePath As String
chromePath = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
Shell (chromePath & " -url http://www.google.com")
End Sub
I found a post on Reddit that says this is much easier using Internet Explorer since Excel/VBA has some built in interop. However, if you're anything like me you abhor IE.
The same Reddit post suggested a third party plug-in called Selenium Basic. I used this answer to download and install it.
The following code successfully opened Google in Chrome and set the text of the search box to "This is a test".
Sub Test()
Dim bot As New WebDriver
bot.Start "chrome", "https://www.google.com"
bot.Get "/"
bot.FindElementByName("q").SendKeys "This is a test"
Stop
End Sub
I used DevTools (F12) to explore the web content and find that the search box has name="q".
Good luck!
I am doing automation of IE using VBA excel and I am not able to select on Tab href="#GST"
<a role=”tab” aria-expanded=”true”
aria-controls=”GST”
href="#GST"jQuery110205664105838982267="18"
data-toggle="tab" jQuery19103093133355326922="601">INVOICE / GST DETAILS</A>
Please help me out
Update I tried this solution
Set HTML = ieApp.document
HTML.querySelector("a[href='#GST']").Click
i tried few solutions but failed.
I tried to check the picture of the error that you had posted in the comment.
You can see that error. It said that "Object required".
If you check your code, you can notice that throughout your code you are using "IE" as an object of the IE browser.
On the problematic line, you can notice that you are using "ieApp" as an object of the IE browser. You can see that "ieApp" object is not available in your code and that's why it is showing this error.
Maybe you found this code online but did not modify it properly.
To correct the issue, you need to replace the "ieApp" with "IE".
Set HTML = IE.document
HTML.querySelector("a[href='#GST']").Click
It can help to fix this error.
I am trying to convert an Excel macro that currently uses Internet Explorer and use the following line of code to extract the web page’s <body> text
x = .Document.DocumentElement.InnerText
Using the Selenium demo, I am able to produce a jpg of the page with Chrome & IE, but Firefox just loads a blank page and IE64 & Edge don’t work on Windows 10.
I have been unable to find the proper VBA command with Selenium to copy the body text to variable ”x”. I only want to read it.
I am trying to do this to make my macro browser independent.
The macro is for my use only.
Jim
You are not making it browser agnostic. You are simply widening the choice of browser to those supported via selenium basic. This brings some problems of its own which you are noticing.
Folders containing the drivers must be on the environmental path or the path passed to selenium webdriver as an argument.
You should use the latest Chrome browser and Chrome driver
You cannot use the latest FireFox browser and driver. It is not supported. I think you need FF v.46.0.1.
If using IE then zoom must be to 100%.
I suggest browsing the issues pages of Github for further known issues
Heuristically, I have heard some banter about problems with Windows 10 and Selenium Basic - would be interested to know if anyone has got this working as I am not on that version.
Review the examples.xlsm provided by selenium basic GitHub site to see which other browsers are supported (e.g. Opera, PhantomJS, FirefoxLight,CEF).
With Chrome you can get the body text with this:
Option Explicit
Public Sub GetInfo()
Dim d As WebDriver, s As String
Set d = New ChromeDriver
Const URL = "https://www.neutrinoapi.com/api/api-examples/python/"
With d
.Start "Chrome"
.get URL
s = .FindElementByTag("body").Text
Debug.Print s
.Quit
End With
End Sub
Other info: https://stackoverflow.com/a/52294259/6241235
For over a year, I've been happily using Selenium code in an Excel document. In the last few weeks, it stopped working, it opens the browser but doesn't open the webpage. The code triggers an application error and aborts. It's not the same error but it's pretty much the same behaviour regardless of whether I use chrome, Firefox or IE.
Here's the code I'm using:
Dim driver As New Selenium.WebDriver
driver.Start "firefox", "http://google.com"
Or...
Dim driver As New Selenium.FirefoxDriver
driver.Start
Anybody can help me debug this annoying behaviour?
Muchas gracias.
OK! I figured it out, thanks to this link:
https://github.com/florentbr/SeleniumBasic/issues/128
Managed to download the latest version of the Chrome Driver
http://chromedriver.storage.googleapis.com/index.html?path=2.24/
Looks like there's no equivalent fix for Firefox, have to roll back to version 46. Hopefully an update will be released, but in the meantime, I'm so very happy to have at least one browser working again.
Cheers guys.
I am trying running a piece of VBA code in excel 2013 to access some data from our intranet site and I am getting a run time error 2147467259 (80004005) - Automation error unspecified error.
Sub AccessWar()
Dim oIE As InternetExplorer
Dim oHTML As HTMLDocument
Set oIE = New InternetExplorer
oIE.Navigate ("http://iscls3apps/WAR40/aspx/WAR40AllReports.aspx")
oHTML = oIE.document
End Sub
I am new to excel VBA and do not have much idea. Any pointers would be helpful
I tried to use IE with VBA too but it seemed that the running don't really care if the loading of the page in IE is done or not!
So I made i little routine that navigate and wait, just by adding
Application.Wait(Now + TimeValue("0:00:05"))
after every navigate... No super efficient but VBA is not made to parse information on the web, you could use so more approriate languages if you are willing to! ;)