Reputation: 165
Here is my code.
from selenium import webdriver
chrome_options = webdriver.ChromeOptions();
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']);
options = webdriver.Chrome(options=chrome_options)
options.get('https://www.google.com/')
images = options.find_elements_by_tag_name('img')
for image in images:
print(image.get_attribute('src'))
options.close()
when i run this code i get this error
**Traceback (most recent call last):
Python\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "Python\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "Python\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified**
Kindly check if i have made any mistakes in the code or if you understand this error do let me know Thanks
Upvotes: 0
Views: 272
Reputation: 598
You would need to add the path to your chrome driver when you declare your driver.
driver = webdriver.Chrome(options=chrome_options, executable_path=r"C:\path\to\chromedriver.exe")
Upvotes: 3
Reputation: 101
First download and install browser driver from https://link.jianshu.com/?t=https://sites.google.com/a/chromium.org/chromedriver/ Unzip and put it in a directory like "browserdriver" and change your code as follows:
from selenium import webdriver
browser = webdriver.Chrome(r"C:\browserdriver\chromedriver.exe")
browser.get("http://www.google.com")
Upvotes: 3