Selenium opens only Google Chrome (using webdriver-manager) - python

Im trying to run selenium on Brave Browser instead of Google Chrome.
As the docs indicate in (https://pypi.org/project/webdriver-manager/#use-with-edge), I should input this exactly and Brave Browser will run, except it wont at all, it will run only Google Chrome
This is the code im using:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as BraveService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType
import time, urllib3.request
driver = webdriver.Chrome(service=BraveService(ChromeDriverManager(chrome_type=ChromeType.BRAVE).install()))
driver.get("https://www.google.com/")
time.sleep(5)
It will only run Google Chrome instead of Brave Browser, anyone could please try and help me out to run on Brave Browser using webdriver_manager?
Thanks

If you have Brave Browser installed on your computer, you can set the binary location of the webdriver.ChromeOptions to the location of brave.exe on your computer. In my case, the brave browser program is located here:
"C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"
Here is an example of how to do this:
Code:
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as BraveService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType
option = webdriver.ChromeOptions()
option.binary_location = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"
driver = webdriver.Chrome(service=BraveService(ChromeDriverManager(chrome_type=ChromeType.BRAVE).install()), options=option)
driver.get("https://www.google.com")

Related

Python Selenium opens Website but then Website closes

I wanna write a programm that opens a website for me and doesnt closes it right after
I tried to open a website and expected it to stay open but it didnt
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service_object_name = Service(r'C:\SneakerPython\chromedriver.exe')
options_name = webdriver.ChromeOptions()
options_name.add_argument("--start-maximized")
browser = webdriver.Chrome(service=service_object_name, options=options_name)
browser.get("https://www.solebox.com/de_DE/p/jordan-air_jordan_1_retro_high_og_%22gorge_green%22-gorge_green%2Fmetallic_silver-wht-02142227.html")
You can add the option detach to let your browser open after your code has been executed :
detach (Boolean) — whether browser is closed when the driver is sent the quit command
I have also modified your code adding ChromeDriverManager that allows to dynamically install the correct chromedriver for your machine.
Just run the following command in your terminal:
pip install webdriver-manager
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options_name = webdriver.ChromeOptions()
options_name.add_argument("--start-maximized")
options_name.add_experimental_option("detach", True)
browser = webdriver.Chrome(
service=Service(ChromeDriverManager().install()), options=options_name
)
browser.get("https://www.solebox.com/de_DE/p/jordan-air_jordan_1_retro_high_og_%22gorge_green%22-gorge_green%2Fmetallic_silver-wht-02142227.html")

Why isn't this Selenium opening the website I'm requesting?

import time
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument(r"--user-data-dir=C:\Users\Owner\AppData\Local\Google\Chrome\User Data")
options.add_argument(r"--profile-directory=Profile 11")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get('https://www.facebook.com')
time.sleep(25)
driver.quit()
I'm attempting to write a script that opens google, picks a Chrome profile, and goes to a website. The code above opens google and signs into the profile but it does not go to Facebook. Does anyone have any idea why?

Python Selenium Use User Profile Chrome

I will do a project by using selenium. But there is a problem for me. I have to use chrome with my settings. My websites login, my history...
But when I use the selenium, It creates a new chrome browser that with a default settings. No Websites login here and others.
My code:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
driver =webdriver.Chrome(ChromeDriverManager().install())
How can i use my current chrome settings or how can I change webdriver by location.
For example(maybe):
driver =webdriver.Chrome(location="C\\Users\\Desktop\\chrome.exe)
I fix my problem with this way:
from selenium import webdriver
import time
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\Fatih\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument('--profile-directory=Default')
driver = webdriver.Chrome(executable_path="chromedriver.exe", options=options)
my "chromedriver.exe" is in same path with my python files.

Module selenium.webdriver has no attribute "get"

I've been trying to run a script in Python to make Chrome open up to a specific page. Here is my code so far
Code part 1
Code part 2
The code is
from selenium import webdriver as wd
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
Then
driver = wd.Chrome()
driver.implicitly_wait(5)
Then
driver.get("https://www.facebook.com")
Despite the error message in the screenshot after the second cell, Chrome opens when I run the script. It just opens to a blank page. I've tried changing the name of driver and wd and webdriver and I get the "module selenium.webdriver has no attribute "get"" every time. This post from yesterday is similar to what I'm having trouble with
but the solution isn't working for me.
Not sure, but try one of the following:
remove wd as it causing misleading
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver = webdriver.Chrome()
driver.implicitly_wait(5)
or this
from selenium import webdriver as wd
from webdriver_manager.chrome import ChromeDriverManager
driver = wd.Chrome(ChromeDriverManager().install())
driver = wd.Chrome()
driver.implicitly_wait(5)
But please don't mix between them.
I prefer the first option.

Chrome opens with “Data;” with selenium chromedriver

Trying to open "Google" or any other page (website) from Chrome via selenium chrome driver in python.
The code is :
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
import time
driver = webdriver.Chrome()
driver.get('https://google.com')
However, this opens my chrome window with the specified link and "data;" tab.
Why that data; tab opens? How to fix it?
Using latest versions of Chrome and Chromedriver
You don't need as much module for this just remove all of those apart from:
from selenium import webdriver
And try again you will not get another tab with congaing data.
import time
time.sleep(1)
driver.switch_to.window(driver.window_handles[1])
driver.close()
driver.switch_to.window(driver.window_handles[0])
time.sleep(1)
I'm not sure if its the same problem, but some time ago I made an exe script to run in another PCs and in one of the PCs selenium just didn't worked with Chrome.
This is the question I posted, but the answers didn't help me, hope it works with you: Chromedriver do not open a new session, it opens a new tab in a existing session
If it doesn't work, I made a workaround to run with Firefox instead of Chrome to ensure it would work properly.
With selenium 4 (or newer), you can use the following code to launch a new browser, (without the Chrome is being controlled message), and then the browser navigates to Google in the same tab:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
service = ChromeService()
driver = webdriver.Chrome(service=service, options=options)
driver.get('https://google.com')

Categories