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
Related
I installed the selenium module with pip installer. Then I tried to make the code to open firefox, then open a new tab to go to google.
Code:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.google.com")
The expected result should have opened firefox and then go to google.com.
But what actually happened was the program didn't produce any error, it just didn't open firefox, and the screen wasn't frozen either.
Download a matching version of Geckodriver and unpack the geckodriver.exe to the location where current user can execute programs from (normally it's any place inside your home folder)
Amend your code to include the location of the aforementioned geckodriver like:
driver = webdriver.Firefox(executable_path="/path/to/the/geckodriver/binary")
If this doesn't help - provide the path to the Firefox executable as well:
driver = webdriver.Firefox(executable_path="/path/to/the/geckodriver/binary", firefox_binary="/path/to/firefox/binary")
Instead of steps 2 and 3 you can add both firefox and geckodriver to your OS PATH
References:
Selenium with Python - Getting Started
Selenium With Python
Selenium using Python - Geckodriver executable needs to be in PATH
Running Python Selenium with Chromedriver is not working, my screenshots shows how it looks now, i dont know why
OS is MACOSX Latest Version (High Sierra)
i just do:
options = Options()
driver = webdriver.Chrome(chrome_options=options)
driver.set_window_size(1400, 800)
driver.delete_all_cookies()
driver.get("https://google.de")
i already tried to fix it myself with:
reinstalled python through brew
uninstalled miniconda
uninstalled virtuelenv
uninstalled chrome
installed chrome
replaced chromedriver with latest one
used a custom chromedriver from custom chrome folder
Opening normally Chrome
not through python selenium works without any issue
(btw geckodriver is working, i don't know what happened im running everything now without problems for 5 months something happened that it got fucked )
HOW IT LOOKS WITH PYTHON CODE:
HOW IT RUNS OPEN CHROME NORMAL MANUALLY:
Okay i found the solution
if you set this preference wrong:
options.add_experimental_option('prefs', {'intl.accept_languages': 'nl_NL'})
you HAVE to overwrite it with a correct language value.
like this:
options.add_experimental_option('prefs', {'intl.accept_languages': 'nl'})
This preference seems to stay saved somewhere and is always active even if deleting the line, its active until you overwrite it with a correct language value.
Even uninstalling chrome, chromedrive, selenium, python and install them from scratch this wrong value was active when running my code.
seems like only overwriting it with a new correct value, chrome forces to reload
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")
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.
This is embarrassing to ask because it seems like something with so slim chance of error. I wouldn't think this would be difficult, but I've been plugging away at this for almost 3 hours now and it's giving me a headache. I've read several dozen stackoverflow threads and Google threads.
I've installed PhantomJS, added it to my System Variables PATH, and it works properly in the command line. I also installed Selenium earlier with easy_install.
The error I get is:
__init__ C:\Python27\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\phantomjs\webdriver.py 50
start C:\Python27\lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\phantomjs\service.py 66
WebDriverException: Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen
Here's my code:
from selenium import webdriver
driver = webdriver.PhantomJS(executable_path="C:\Python27\misc\phantomjs\phantomjs.exe")
I also tried:
from selenium import webdriver
driver = webdriver.PhantomJS()
I get the same error message. This has to be something simple that I'm doing wrong. I'd appreciate any comments or answers.
Windows 7 64 bit
Python 2.7
This may have been a version issue for you, but since I just went through setting this up on my Windows 7 PC without issues I'm going to share my 'journey' here.
First of, I'm more used to the Mac/Linux Terminal and having the python package manager pip at my disposal is essential to me. After installing Python 2.7.8 and adding ;c:\Python27 to my PATH I noticed that pip isn't included with Python versions lower than 2.7.9, so I had to add it myself. Afterwards I added ;c:\Python27\Scripts to my PATH.
After that fetching the python package selenium was as easy as typing the following into the cmd:
pip install selenium
Then I downloaded the phantomjs-1.9.7-windows.zip from here, unzipped it and placed it here:
C:\Python27\misc\phantomjs-1.9.7-windows\phantomjs.exe
From there I had a working Python 2.7/Selenium Webdriver/PhantomJS example for Windows 7.
from selenium import webdriver
import os
phantomjs_path = "C:\Python27\misc\phantomjs-1.9.7-windows\phantomjs.exe"
browser = webdriver.PhantomJS(executable_path=phantomjs_path, service_log_path=os.path.devnull)
browser.set_window_size(1400, 1000)
browser.get("https://stackoverflow.com/")
print browser.title
Note that I added the argument service_log_path=os.path.devnull to the function webdriver.PhantomJS() to prevent PhantomJS from creating a ghostdriver.log in the directory of the python file being executed.
I had the same problem running Python 3.4 on Windows Server 2012 R2. PhantomJS was failing to create the ghostdriver.log file. I followed these steps that fixed it for me:
Made sure phantomjs.exe was not showing "Blocked" on the File Properties|Security tab, and ran it as standalone app to confirm.
Deleted an old copy of the ghostdriver.log file that was in the same directory.
Ran python REPL from the console while checking to see if the code that instantiated the driver was getting called successfully.
browser = webdriver.PhantomJS(executable_path='phantomjs.exe', desired_capabilities=argdc, service_args=svc_args)
Do you any other file or directory with a same name , or a file of coding (like .. phantomjs.py) which you have named same as phantomjs is so then rename it to something else. i hope it works