Problem:
I just want to open a URL with selenium in python but it didn't work.
This is my current code:
from selenium import webdriver
path='C:\Program Files (x86)\chromdriver.exe'
url='https://anywebpage.de'
browser = webdriver.Chrome(path)
Technical specification:
Windows 10 Pro 64 bit Python Version 3.9
I get this error message:
"Message: 'chromdriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home"
I cannot find a solution out in the documentation
Has anyone else an idea?
The exe.file is in the correct path stored.
from selenium import webdriver
PATH = "C:\Chrome Webdriver\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("Your-website-here")
If you are using windows, press shift and right click on chromedriver to copy it's path Image
"C:\Chrome Webdriver\chromedriver.exe" was my own personal path, you must copy yours.
Also, in your code above, your file path is missing an "e" in chromedriver
Related
so I have started working on selenium, and this is my first time working with it, the code provided below opens chrome but doesnt open the url mentioned in the .get function.
from selenium import webdriver
import time
# open chrome and access the page
driver = webdriver.Chrome("C:\Program Files\Google\Chrome\Application\chrome.exe")
driver.get('https://dex.onxrp.com/?project=XREEFS')
time.sleep(5)
driver.close()
I have installed the selenium pip library, do i need something else as well for it to load the link?
Using selenium3 the default argument which can be passed within webdriver.Chrome() is the value of the KEY executable_path i.e. the logical/absolute path of the ChromeDriver executable but not of google-chrome executable.
Solution
Ideally, your line of code will be:
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
Though the default browser is IE or Firefox, when I run the program, I want the website to be opened in chrome.
At first, I tried this out--
import webbrowser
import os
path = "C:\Program Files (x86)\Google\Chrome\Application %s"
webbrowser.get(path).open("youtube.com")
But the webpage opened in Ie as my default browser is IE.
Then I tried the below code-
from selenium import webdriver
browser = webdriver.Chrome()
browser.open('https://directory.corp.intranet/cmsviewer/login.html')
But received many errors. Please help me out!!!
Hello and welcome to Stack overflow
try to do this :
import webbrowser
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open('http://docs.python.org/')
good luck
Try maybe the following:
import webbrowser
webbrowser.get('chrome').open("youtube.com")
As it seems that chrome is already registered by default:
https://docs.python.org/3.8/library/webbrowser.html#webbrowser.register
Your selenium code is very likely not working due to the lack web extensions like .net, .com,.org, .aspx etc. So your selenium code should work if it looked like
from selenium import webdriver
browser = webdriver.Chrome()
browser.open('https://directory.corp.intranet.aspx')
After running pip selenium and downloading chromedriver.exe to C:/chromedriver/chromedriver.exe directory. Running my program results in Chrome not being able to open the URL and the following message prompts in a dialog-box:
Chromedriver stopped working
This is my attempt at testing that the source-page could be accessed.
import requests
from selenium import webdriver
Base_url = "https:/www.facebook.com"
driver = webdriver.Chrome(r'C:/chromedriver/chromedriver.exe')
driver.get(Base_url)
print (driver.page_source)
Can someone help me sort this out?
Thank you.
To open Chrome Browser using chromedriver binary you need to pass the argument executable_path along with the absolute path of the chromedriver binary and invoke the proper url as follows :
from selenium import webdriver
Base_url = "https://www.facebook.com/"
driver = webdriver.Chrome(executable_path=r'C:/chromedriver/chromedriver.exe')
driver.get(Base_url)
print (driver.page_source)
I am trying to load a google chrome extension with Selenium WebDriver.
But I receive an error OSError: Path to the extension doesn't exist.
Here is the code I am using:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from os import path
path = "path to chrome driver"
chrome_options = webdriver.ChromeOptions()
chrome_options.add_extension('Adblock-Plus_v1.12.4_0.crx') # ALTERNATIVE 0
driver = webdriver.Chrome(path, chrome_options=chrome_options)
After reading various similar questions on this site I tried the following two alternatives:
# Alternative 1
chrome_options.add_extension('~/Library/Application\ Support/Google/Chrome/Default/Extensions/[Extension ID]/Adblock-Plus_v1.12.4_0.crx')
#Alternative 2
chrome_options.add_extension(path.abspath("Adblock-Plus_v1.12.4_0.crx"))
But none of them work. Alternative 1 gives same error message as the original code whereas Alternative 2 gives error AttributeError: 'str' object has no attribute 'abspath'
Does anyone have a clue what I could be doing differently?
More thank likely, this is because python is referencing the wrong path with what would normally be the home directory shortcut of ~/ in the path. Python will try and run the file from the current directory, so for example if your code is in ~/Dev/testproject, and the code being called above is really trying to run /home/username/Dev/testproject/~/Library/Application Support/Google/Chrome/Default/Extensions/[Extension ID]/Adblock-Plus_v1.12.4_0.crx
Try using the following:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import os
chromedriver = "path to chrome driver"
chrome_options = webdriver.ChromeOptions()
# choose one of the following 2:
chrome_options.add_extension(os.path.expanduser('~/Library/Application\ Support/Google/Chrome/Default/Extensions/[Extension ID]/Adblock-Plus_v1.12.4_0.crx')) # Option 1: if your extension is not also in your project folder
chrome_options.add_extension(os.path.abspath('Adblock-Plus_v1.12.4_0.crx')) # Option 2: if your extension IS in your project folder
driver = webdriver.Chrome(chromedriver, chrome_options=chrome_options)
EDIT: avoid declaring a variable named path since you are importing path from os. This is why you are getting the error on Alternative #2.
I tried to add adblock to the selenium using this code:
chop =webdriver.ChromeOptions()
chop.add_extension('Adblock-Plus_v1.4.1.crx')
driver = webdriver.Chrome(chrome_options=chop)
I got this error:
'OSError: Path to the extension doesn't exist'
what should I do?
You need to provide the full path:
from os import path
chop =webdriver.ChromeOptions()
chop.add_extension(path.abspath('Adblock-Plus_v1.4.1.crx'))
driver = webdriver.Chrome(chrome_options=chop)