After running pip selenium and downloading chromedriver.exe to C:/chromedriver/chromedriver.exe directory. Running my program results in Chrome not being able to open the URL and the following message prompts in a dialog-box:
Chromedriver stopped working
This is my attempt at testing that the source-page could be accessed.
import requests
from selenium import webdriver
Base_url = "https:/www.facebook.com"
driver = webdriver.Chrome(r'C:/chromedriver/chromedriver.exe')
driver.get(Base_url)
print (driver.page_source)
Can someone help me sort this out?
Thank you.
To open Chrome Browser using chromedriver binary you need to pass the argument executable_path along with the absolute path of the chromedriver binary and invoke the proper url as follows :
from selenium import webdriver
Base_url = "https://www.facebook.com/"
driver = webdriver.Chrome(executable_path=r'C:/chromedriver/chromedriver.exe')
driver.get(Base_url)
print (driver.page_source)
Related
so I have started working on selenium, and this is my first time working with it, the code provided below opens chrome but doesnt open the url mentioned in the .get function.
from selenium import webdriver
import time
# open chrome and access the page
driver = webdriver.Chrome("C:\Program Files\Google\Chrome\Application\chrome.exe")
driver.get('https://dex.onxrp.com/?project=XREEFS')
time.sleep(5)
driver.close()
I have installed the selenium pip library, do i need something else as well for it to load the link?
Using selenium3 the default argument which can be passed within webdriver.Chrome() is the value of the KEY executable_path i.e. the logical/absolute path of the ChromeDriver executable but not of google-chrome executable.
Solution
Ideally, your line of code will be:
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
#TLDR I want to use brave browser with selenium written in python but can't find any current solutions that work.
This code works
from selenium import webdriver
option = webdriver.ChromeOptions()
option.binary_location = r'C:\Program Files\BraveSoftware\Brave-
Browser\Application\brave.exe'
driver = webdriver.Chrome(executable_path=r'C:\WebDrivers\chromedriver.exe',
options=option)
driver.get("https://www.google.com")
driver.quit()
but executable_path is deprecated:
C:\Users\USER\PycharmProjects\pythonProject\sol2.py:5:
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path=r'C:\WebDrivers\chromedriver.exe', options=option)
Found this on youtube: https://www.youtube.com/watch?v=VMzmVFA-Gps
# import statements
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
# Declare variables and setup services
driverService = Service('C:/webdrivers/chromedriver.exe')
# 1. Passes the chromedriver path to the service object
# 2. stores the service object in the s variable
driver = webdriver.Chrome(service=driverService)
# 1. Passes service object driverSerice into the webdriver.Chrome
# 2. Stores object in driver variable
# Body (actually doing stuff)
driver.maximize_window() # maximizes the browser window
driver.get("https://www.google.com") # navigates to google.com
myPageTitle = driver.title
# gets the title of the web page stores in myPageTitle
print(myPageTitle) # prints myPageTitle to Console
assert "Google" in myPageTitle
# checks myPageTitle to ensure it contains Google
# clean up
driver.quit() # closes the browser
When I run this code I get:
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
This code works as long as you allow Google Chrome onto your PC. I don't want Chrome on my PC.
The problem is that I can't figure out how to get selenium to use brave instead of Chrome.
As of this writing I am using the following:
Windows 11 Home
Selenium v4.0.0
Python v3.10
ChromeDriver 95.0.4638.69
Brave Browser Version 1.31.91 Chromium: 95.0.4638.69 (Official Build) (64-bit)
Can some one please explain how to make this work with the current (read nondeprecated) code on brave browser? Thanks for your time.
To initiate a brave browsing context you need to:
Use the binary_location attribute to point to the brave binary location.
Use the chromedriver executable to initiate the brave browser.
Code block:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
option = webdriver.ChromeOptions()
option.binary_location = r'C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe'
driverService = Service('C:/Users/.../chromedriver.exe')
driver = webdriver.Chrome(service=driverService, options=option)
driver.get("https://www.google.com")
Note: The DeprecationWarning: executable_path has been deprecated is a harmless warning message which doesn't affects your test execution and you can still ignore it.
References
You can find a couple of relevant detailed discussions in:
How to use Brave web browser with python, selenium and chromedriver?
How to initiate Brave browser using Selenium and Python on Windows
you have to set your path to brave binary.
options.setBinary("Path to brave.exe");
Go through this website:
https://mundrisoft.com/tech-bytes/how-to-execute-selenium-script-in-brave-browser/
I am a complete beginner to selenium and I wrote my first program just to connect to Google.
from selenium import webdriver
path = "C:\\Users\\Home\\Documents\\Python37-32\\Scripts\\Code\\msedgedriver.exe"
driver = webdriver.Edge(path)
driver.get("https://google.com")
print(driver.title)"
My web driver version is 88.0.705.50 (Official build) (64-bit)
I use selenium 3 and I am getting this error while running the code. Also it is opening "data:," for a few seconds then opening Google. Lastly the browser doesn't stay open.
Declare path on a separate line from the import statement
Use raw string in path or double escapes
Code:
from selenium import webdriver
path = r"C:\Users\Home\Documents\Python37-32\Scripts\Code\msedgedriver.exe"
driver = webdriver.Edge(path)
driver.get("https://google.com")
print(driver.title)
What error do you get? It's the default behavior that the browser opens with data:,, then it will direct to the website you want. The browser doesn't stay opened may because the error breaks it.
You can refer to the following steps to automate Edge in python selenium:
Make sure the WebDriver version is the same as the Edge version.
Install the MS Edge Selenium tools using command below:
pip install msedge-selenium-tools selenium==3.141
Sample code:
from msedge.selenium_tools import Edge, EdgeOptions
options = EdgeOptions()
options.use_chromium = True
driver = Edge(executable_path = r"C:\Users\Home\Documents\Python37-32\Scripts\Code\msedgedriver.exe", options = options)
driver.get("https://google.com")
print(driver.title)
I'm trying to code an automation function which opens the entered URL. The code works if I'm not working with Chrome browser; but doesn't work with Chrome browser: it fails to detect my Chrome Browser and returns the error "could not find runnable browser".
Code:
import webbrowser
def visitwebsite():
url = input('Enter url: ')
webbrowser.get('chrome').open_new_tab(url)
Tried already 'chrome' - 'google-chrome' and redirecting it directly to the path. Maybe i did it wrong
The code is simple. You need to install selenium for this.
from selenium import webdriver
driver = webdriver.Chrome(executable_path='path to chromedriver.exe')
driver.get('https://www.google.com)
I am using selenium to crawl a javascript website, the issue is that, a Firefox browser opens up, but the call for the URL is not done. however, when I close the browser, it is then that call for URL is done and of course I get the missing driver exception. what do you think the issue comes from.
knowing that:
all programs are up-to-date
my solution works fine, in local, but when I try to deploy it on the server, I start having issues
Example: at my local machine, I run this script and everything goes smooth, however when I run it a server (Linux), only the browser opens up and no get URL is called
from selenium import webdriver
import time
geckodriver_path = r'.../geckodriver'
driver = webdriver.Firefox(executable_path= geckodriver_path)
time.sleep(3)
driver.get("http://www.stackoverflow.com")
I end up finding the solution :
from selenium import webdriver
import time
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
geckodriver_path = r'/path_to/geckodriver'
binary = FirefoxBinary(r'/usr/bin/firefox')
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities["marionette"] = False
driver = webdriver.Firefox(firefox_binary=binary,
executable_path= geckodriver_path,
capabilities=capabilities)
time.sleep(3)
driver.get("https://stackoverflow.com/")
time.sleep(6)
driver.close()
# solution from:
# https://github.com/SeleniumHQ/selenium/issues/3884
# https://stackoverflow.com/questions/25713824/setting-path-to-firefox-binary-on-windows-with-selenium-webdriver