Spyder randomly fails to locate chromedriver - python

I am using python via spyder to do some web scraping. My code seems to be working fine, but after a few times I open and close chromedriver during the same session of spyder, when I run
from selenium import webdriver
browser = webdriver.Chrome(executable_path = 'C:/Python34/Scripts/chromedriver.exe')
I get the error message
WebDriverException: 'chromedriver.exe' executable needs to be available in the path.
I tried downloading the latest version of chromedriver, but the issue persists. The suggestion I found here says to download the 64bit version of chromedriver, but I was not able to get a hold of that. Is this solvable anyhow? Any help much appreciated.
UPDATE:
Using chromedriver, this was solved using quit() instead of close() to end each session of chrome.

Try:
browser = webdriver.Chrome("C:/Python34/Scripts/chromedriver.exe")

Related

DPC_Watchdog_Violation when ever I try running my code

from selenium import webdriver
driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe")
driver.get("https://www.facebook.com/")
After a minute of running that code i get the DPC_Watchdog_Violation error, I made sure I had the right chrome version for chrome-driver, I also tried a different chrome version that goes with chrome driver but still same error.
Try running the selenium with Firefox + geckodriver combination. It worked for me and didn't crash a single time. Seems that chromedriver has a bug in it or something.
Here are some useful links to getting the correct driver version:
Correct driver version table
Driver downloads
Selenium also has an IDE which has very useful functions like action recordings. I highly recommend it as you can export python files from it and then use the generated commands without having to find all of the ids/classes.

Selenium is not accessing drivers properly

I am trying to access a browser using Selenium.
My first Python code try is this:
from selenium import webdriver
browser = webdriver.Chrome()
It gives me the error message:
'chromedriver' executable needs to be in PATH.
Some other answers on here suggest I point to the path manually. So I try:
from selenium import webdriver
chromedriver_loc = '/usr/local/bin'
driver = webdriver.Chrome(executable_path=chromedriver_loc)
This gives me the error message:
'bin' executable may have wrong permissions.
I am using a Mac and running an Anaconda Spyder environment.
The chromedriver file is in the /usr/local/bin. When I use GetInfo from the Finder program, the 'locked' selection is unchecked, but grayed out so I can't check or uncheck it.
The same error messages appear if I substitute Firefox for Chrome.
Can anybody help me provide the right 'permissions' so I can properly use Selenium? Please let me know if you need additional information, as this is my first question on here.
You should use the full path including the filename:
chromedriver_loc = '/usr/local/bin/chromedriver'

Selenium seems not working properly with Firefox 49.0, Is anyone familiar with this?

I have been trying to load my Firefox (Mozilla Firefox 49.0), with simple python script and with the assistance of selenium-2.53.6 on Ubuntu 16.04.1 LTS, but even selenium's basic example 0 doesn't work:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/')
I always get after about 5 seconds a timeout, and firefox crashes with the following message:
"Can't load the profile. Profile Dir: /tmp/tmpl5qlfokc If you specified a log_file in the FirefoxBinary constructor, check it for details"
so I created a specific firefox profile (profile -p), and used it, wrote:
profile =
webdriver.FirefoxProfile('absolute path to profile folder')
driver = webdriver.Firefox(profile)
but still it seems no matter what I do, the browser crashes after 5 seconds.
Read the post can't load profile on firefox and followed the instructions but still unfortunately the same result. does anyone know how to overcome this the issue?
Thank you all!
For firefox 49.0 you need selenium 3(it's in beta stage, that's why you can't download it with pip -U) and geckodriver.
try this:
wget https://github.com/mozilla/geckodriver/releases/download/v0.10.0/geckodriver-v0.10.0-linux64.tar.gz
tar xzvf geckodriver-v0.10.0-linux64.tar.gz
cp geckodriver /usr/bin/
pip install selenium==3.0.0b3

How do I install ChromeDriver on Windows 10 and run Selenium tests with Chrome?

We have an Ubuntu server which we use for running Selenium tests with Chrome and Firefox (I installed ChromeDriver) and I also want to run the tests locally on my Windows 10 computer. I want to keep the Python code the same for both computers. But I didn't find out how to install the ChromeDriver on Windows 10? I didn't find it on the documentation [1, 2].
Here is the code that runs the test in Chrome:
import unittest
from selenium import webdriver
class BaseSeleniumTestCase(unittest.TestCase):
...
...
...
...
def start_selenium_webdriver(self, chrome_options=None):
...
self.driver = webdriver.Chrome(chrome_options=chrome_options)
...
I also found How to run Selenium WebDriver test cases in Chrome? but it seems to be not in Python (no programming language is tagged, what is it?)
Update #1: I found some Python code in https://sites.google.com/a/chromium.org/chromedriver/getting-started, but where do I put the file in Windows 10 if I want to keep the same Python code for both computers?
Update #2: I downloaded and put chromedriver.exe in C:\Windows and it works, but I didn't see it documented anywhere.
As Uri stated in the question, under Update #2, downloading the latest release of chromedriver and placing it in C:\Windows corrects the issue.
I had the same issue with Chrome hanging when the browser window opens (alongside a command prompt window).
The latest drivers can be found at:
https://sites.google.com/chromium.org/driver
The version in the chromedriver_win32.zip file is working on my 64-bit system.
Download the chromedriver.exe and save it to a desired location
Specify the executable_path to its saved path
The sample code is below:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(executable_path="path/to/chromedriver.exe", chrome_options=options)
driver.get("example.html")
# do something here...
driver.close()
As Uri stated in Update #2 of the question, if we put the chromedriver.exe under C:/Windows, then there is no need to specify executable_path since Python will search under C:/Windows.
Let me brief out the requirements first.
You need to download the chrome web driver zip from here. https://chromedriver.storage.googleapis.com/index.html?path=2.33/
Extract the file and store it in a desired location.
Create a new project in Eclipse and include the following code in your class.
System.setProperty("webdriver.chrome.driver", "C:\\temp\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
Explanation : System.setProperty(key,value):
Key is default and same for all the systems, value is the location of your chromedriver extract file.

Error when trying to use webdriver.PhantomJS() from Selenium

Windows7, selenium 2.45.0, python 2.7.5, phantomjs 2.0.0
Installed selenium with pip (seems to be working fine otherwise), installed phantomjs from http://phantomjs.org/download.html. Moved the folder for phantomjs into a folder within C:\Python27 and then added C:\Python27...\bin\phantomjs to system Path (tried both phantomjs and phantonjs.exe). Whenever driver = webdriver.PhantomJS() is used this occurs...
Error:
raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
WebDriverException: Message: Unable to start phantomjs with ghostdriver.
Screenshot: available via screen
Tried every solution I could find so far: reverting to version 2.37.0, trying phantomjs vs phantomjs.exe in path, altering the service.py file, installing it through node.js, rebooting after adding it to path, and using executable_path=.... within the PhantomJS() parameter. Any additional ideas?
PhantomJS recently dropped Python support altogether. However, PhantomJS now embeds Ghost Driver.
A new project has since stepped up to fill the void: Ghost.py (http://jeanphix.me/Ghost.py/). You probably want to use that instead:
from ghost import Ghost
ghost = Ghost()
page, extra_resources = ghost.open("http://jeanphi.fr")
assert page.http_status==200 and 'jeanphix' in ghost.content

Categories