I am trying to open Chrome with Selenium but when I run the code I get an error message stating:
Cannot find Chrome library.
Sub driver()
Dim selenium As New selenium.WebDriver
selenium.Start "chrome", "http://google.com"
selenium.Get "/"
End Sub
I have installed the latest version of Selenium, and updated the Chromedriver. I think the problem is that Chrome.exe is not in the location selenium expects it to be. Does anybody know how to change the path to Chrome.exe?
Related
I installed Selenium via pip and I've installed the appropriate Chrome Driver too and have been able to webscrape successfully.
I then realised you could execute Selenium from VBA and so I tried doing the following:
Dim driver As SeleniumWrapper.WebDriver
Set driver = New SeleniumWrapper.WebDriver
driver.Start "chrome", "www.google.co.uk"
driver.Open "/"
End Sub
I can see it didn't work as I need the Selenium Wrapper, So I've installed that via pip too.
However, I still can't find the option under Tools --> References for Selenium Type Library as stated in many tutorials. This usually allow VBA to execute the code..
Any suggestions are welcome!
I work with python 3.7 on windows and I want to write a script that print the actual active urls on browsers (chrome and firefox), I found the script:
import webbrowser
webbrowser.open(the url)
but this script allows to open the url not to find the active urls.
can someone help me
Here you need to download and install pywin32 and import these modules in your script like this -
import win32gui
import win32con
#to get currently active windows
window = win32gui.GetForegroundWindow
Or to get the Google Chrome window handle
win32gui.FindWindow
You can use selenium module and loop through all open tabs.
This code prints all open tabs of chrome and firefox:
from selenium import webdriver
chromeDriver = webdriver.Chrome()
firefoxDriver = webdriver.Firefox()
for handle in chromeDriver.window_handles[0]:
chromeDriver.switch_to.window(handle)
print(chromeDriver.current_url)
for handle in firefoxDriver.window_handles[0]:
firefoxDriver.switch_to.window(handle)
print(firefoxDriver.current_url)
Note:
This code is inefficient and should change to use only one loop.
I want to use Excel VBA with Selenium Wrapper to launch Google Chrome and then control Chrome to serve pages I specify so that I can scrape data from them. I can't launch Chrome from VBA.
I'm running Excel 2010. In VBA editor I have added Selenium Type Library to the references. I've verified that I'm running ChromeDriver 2.33.506120. In the code below I know driver is recognized as a driver because I'm getting Intellisense options. I have the ChromeDriver in a folder in Program Files. I have set this folder in the Path list. When I run the code, I get: Run Time Error 2147024894, Automation Error, The system cannot find the file specified. I have also tried driver.start with same results. I have tried changing the name of the browser to "Google Chrome".
Sub MyTest()
Dim driver As New ChromeDriver
driver.Get "https://www.google.com"
End Sub
I expected to launch Chrome. What I get is an error message.
Error Message
Trying to get started with Selenium/Excel VBA to do some scraping. Cannot get started due to Run-time error '33'.
Search only revealed one case where the problem was addressed by matching Selenium Version with correct ChromeDriver Version. I've done that with .75 and .74 Chrome browser versions, and corresponding correct ChromeDriver version. Same error regardless.
Public Sub seleniumtutorial()
Dim bot As New WebDriver
bot.Start "chrome", "http://google.com"
bot.Get "/"
bot.TakeScreenshot.SaveAs (ActiveWorkbook.Path + "/screenshot.jpg")
bot.Quit
'quit method for closing browser instance.
End Sub'
bot.Start line elicits Run-time error '33'.
Run-time error '33':
SessionNotCreatedErro
session not created exception
from unkown error: Runtime.executionContextCreated has invalid 'context"
{"auxData":{frameId":"D306.......1C","isD
(session info: chrome=75.0.3770.142)"
Currently
ChromeDriver 75.0.3770.140
Google Chrome Version 75.0.3770.142 (Official Build)
Windows 10 Pro, 1809
Selenium Basic 2.0.9.0
Excel 360, 64 Bit
I'm currently trying to learn VBA in Excel and I've written a simple procedure where I should be able to launch Chrome and click on a button. Problem is that I'm getting a Run-time error '0': KeyNotFoundError Dictionary key not found:status whenever I try to use the .click method.
I downloaded the Selenium Basic from the following site https://florentbr.github.io/SeleniumBasic/ activated the reference in VBA and downloaded the latest chromedriver
Sub driver()
Dim driver As New Selenium.WebDriver
Set driver = New Selenium.WebDriver
driver.Start "chrome"
driver.Get "http://www.google.com"
Set Element = driver.FindElementByName("btnI")
Element.Click
End Sub
This is just a simple code where I launch Chrome and go to Google and click the "I feel Lucky" button.
A quick test for firing that button and I needed to use javascript
driver.ExecuteScript "document.querySelector('[name=btnI]').click();"
If the error remains I suggest checking chromedriver.exe is the right version for your Chrome browser and do a selenium re-install and check the selenium type reference as usual in the VBE.
The latest version of Chrome is throwing "KeyNotFoundError Dictionary key not found:status" error.
Try replacing your Chromedriver with version 2.46. Here is the link: https://chromedriver.storage.googleapis.com/index.html?path=2.46/
Below is the code I have tried and it worked perfectly fine for me. Let us know if this solution worked for you! :)
Sub driver()
Dim driver As New Selenium.WebDriver
Set driver = New Selenium.WebDriver
driver.Start "chrome"
driver.Get "http://www.google.com"
driver.FindElementByCss("#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input[type=submit]:nth-child(2)").Click
End Sub