HansViz
HansViz

Reputation: 13

Cannot open up URL with selenium python, but the browser is succesfully opened

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
import datetime


ch_options = webdriver.ChromeOptions()
ch_options.add_argument("--user-data-dir=C:\\Users\\Dossy\\AppData\\Local\\Google\\Chrome\\User Data")


chrome = webdriver.Chrome(options=ch_options)

chrome.get("https://www.google.com/")

this code only open up the chromedriver with my profile, but couldn't redirect to a link

Upvotes: 1

Views: 1603

Answers (4)

Lucky Yadav
Lucky Yadav

Reputation: 59

If you have problem in first solution and try this: First copy the of chrome driver path: enter image description here

Then,go to the "This PC" and right click on it and then go to the properties: enter image description here

After it go to the advanced system setting: enter image description here

Then, click on Environment Variable enter image description here

Then,In system variable click on Path and then click on edit: enter image description here

Then, click on new : enter image description here

After it,paste the copied path with \chromedriver.exe then click on "Ok": enter image description here

and click "Ok" on all the tabs That's it Now try it Comment if you are having still problem in this.

Upvotes: 0

Lucky Yadav
Lucky Yadav

Reputation: 59

Instead of writing this:

ch_options = webdriver.ChromeOptions()
ch_options.add_argument("--user-data-dir=C:\\Users\\Dossy\\AppData\\Local\\Google\\Chrome\\User Data")

you can directly give the path

ch_options = webdriver.Chrome('**HERE GIVE  YOUR FULL PATH OF chromedriver.exe**')

like:

chrome = webdriver.Chrome('C:\\Users\\Lucky\\Downloads\\.zip\\chromedriver.exe')

Your browser will open and it and will also redirect you to the link.

Upvotes: 1

Abhilash BK
Abhilash BK

Reputation: 7

Making it so simple and short: Make sure to add the chrome driver path correctly

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
import datetime

PATH = r"C:\Program Files (x86)\chromedriver.exe"    # Path where u have downloaded the driver

driver = webdriver.Chrome(PATH)

driver.get("https://www.google.com")

This will work hopefully!

Upvotes: 1

Kishan Yadav
Kishan Yadav

Reputation: 96

Try this with your correct driver path

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time
import datetime

chromedriver = 'path of chrome driver till chromedriver.exe'
driver = webdriver.Chrome(chromedriver)
driver.get("https://www.google.com/")

Upvotes: 1

Related Questions