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.
Related
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")
After switching to ChromeDriverManager().install(),I am not able to use default profile.Any workaround there so that I can avoid logging in every time?
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),....)
used many solutions found here, but still not working.
directories:
user-data-dir=C:\Users\xxx\AppData\Local\Google\Chrome\User Data
user-data-dir=C:\Users\xxx\AppData\Local\Google\Chrome\User Data\Default
To use the default profile, you have to mention the path like below:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
options = Options()
# path of the chrome profile's parent directory
options.add_argument(r"user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data")
# name of the directory
options.add_argument("--profile-directory=Default")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
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?
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?
I'm trying to launch some browser (Chrome) functions by sending shortcuts
I have tried several methods but they all cannot work.
I do this by following these steps
Initialize the browser
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
options = Options()
options.add_argument("--user-data-dir="+r"path_to_user_data")
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())
,options=options
)
Through actionchain
ActionChains(driver).key_down(Keys.CONTROL).key_down('T').key_up('T').key_up(Keys.CONTROL).perform
Through send_key
driver.find_element(by=By.XPATH,value="/html/body").send_keys(Keys.CONTROL+"T")
But it doesn't work. This is confused for me. Why it cannot work?
It is possible to open a new tab and switch to it with a single command
driver.switch_to.new_window()
To Open a blank new tab you can use the below:
driver.execute_script("window.open('');")
Switch to the new window
driver.switch_to.window(driver.window_handles[1])