Don't make changes to user data Selenium - python

I'm currently using user data when using selenium chrome webdriver which I have running on a cronjob:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
options = webdriver.ChromeOptions()
options.add_argument("./chromedriver_setup/chrome-data")
service = Service("./chromedriver_setup/chromedriver")
driver = webdriver.Chrome(service=service, options=options)
After each job, the user data is changed, is there a way to remove these changes between each job?

Related

Selenium opens only Google Chrome (using webdriver-manager)

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")

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.

Google chrome closes automatically after executing Python selenium code despite using the option class to keep it open

I have checked online and it was mentioned that Selenium closes the browser after running unless you use the option module or the driver.quit() or driver.close() functions but I used the option as shown in the code below but Chrome still closes after 2-3 seconds.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
chrome_driver_path = r"C:\Development\chromedriver.exe"
serv = Service(chrome_driver_path)
driver = webdriver.Chrome(service=serv, options=chrome_options)
driver.get("https://www.google.com")

Categories