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

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?

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

Web Scraping: How to click button in selenium without opening webdriver?

I am using selenium scraping code in Windows VPS, Now code open chrome browser in order to click button, but I need to use the code in Ubuntu VPS.
As you know Ubuntu VPS don't provide any UI. So I need to click button in selenium without opening webdriver - chrome browser.
I tested --headless option but not works.
Follow my code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
chrome_options = Options()
# chrome_options.add_argument('--headless')
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options = chrome_options)
link = "site url"
driver.get(link)
button = driver.find_element(By.CSS_SELECTOR, "button")
button.click()
print("Clicked Accept_BTN")

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.

Categories