I'm trying to work through http://blog.likewise.org/2013/04/webdriver-testing-with-python-and-ghostdriver/. My development environment is a usb drive on win7. I have phantomjs.exe on:
f:/phantomjs.exe
Using the python REPL I have done the following based on the article:
>>> from selenium import webdriver
>>> driver = webdriver.PhantomJS(executable_path="F:\phantomjs.exe")
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "F:\envs\r1\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 50, in __init__
self.service.start()
File "F:\envs\r1\lib\site-packages\selenium\webdriver\phantomjs\service.py", line 66, in start
raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
WebDriverException: Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen
How can I fix this?
Following Can't run PhantomJS in python via Selenium, I uninstalled selenium from my virtualenv and ran:
pip install selenium==2.37
So far this has been working for me , although the above articles indicates there are some problems at least.
Related
I have properly install selenium and chromedriver and wanted to execute this below code at python
import selenium
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r"C:\Users\SM.Nibir\Desktop\Python\chromedriver_win32\chromedriver.exe")
but I am getting these errors on my output panel
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/SM. Nibir/Desktop/Python/import os.py", line 3, in <module>
driver = webdriver.Chrome()
File "C:\python\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\python\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Who can I solve this problem and make this code work properly?
first of all, your first mistake is that you wrote "import selenium from.."
so the order has to be that way:
from selenium import webdriver
driver=webdriver.Chrome(executable_path=r"C:\Users\...chromedriver.exe")
ofcourse that you need to change the path for the correct location of your chromedriver.exe file.
let me know if it helps.
I'm trying to run a Python script in a CentOS server. However, I've been unable to install Google Chrome (I've read it is no longer supported by CentOS) so I decided to try with Firefox. However, I get the following error when trying to run it with Firefox.
Traceback (most recent call last):
File "/home/uscomplianceserv/public_html/scrapdata/FMCSAScraper.py", line 73, in <module>
init_selenium()
File "/home/uscomplianceserv/public_html/scrapdata/FMCSAScraper.py", line 40, in init_selenium
webdriver.Firefox(firefox_options = options, executable_path='/home/uscomplianceserv/public_html/scrapdata/geckodriver')
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 133, in __init__
if options.binary is not None:
AttributeError: 'Options' object has no attribute 'binary'
This is what I'm using:
Centos 6.10
Python 2.7
Selenium 3.14.0
Firefox 45
Geckodriver v0.21.0
This is the selenium webdriver initialization function:
def init_selenium():
global driver, page
options = Options()
options.add_argument("-headless")
driver = webdriver.Firefox(firefox_options = options, executable_path='/home/uscomplianceserv/public_html/scrapdata/geckodriver')
driver.get(url)
I am doing some beginner Selenium to automate a task in the browser. I have installed Selenium using pip install selenium and I know it installed successfully because I saw the following message: Successfully installed selenium-3.9.0.
Okay so that's clear Selenium is up and working.
I want to run this python file:
from selenium import webdriver
browser = webdriver.Firefox()
type(browser)
browser.get('http://inventwithpython.com')
However, when I run this using the terminal, I get the following error:
mustafas-mbp:PlayDivya mustafahoda$ python playDivya.py
Traceback (most recent call last):
File "playDivya.py", line 4, in <module>
from selenium import webdriver
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 22, in <module>
import httplib as http_client
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 69, in <module>
from array import array
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so, 2): Symbol not found: __PySlice_AdjustIndices
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so
Any help would be super helpful. This is a very simple script and I have no idea why this is happening!
Thanks in advance!
The error says it all :
Traceback (most recent call last):
File "playDivya.py", line 4, in <module>
from selenium import webdriver
.
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so, 2): Symbol not found: __PySlice_AdjustIndices
Reasons and Solution
This issue can arise when you install a new version of python. In those cases you may need to run hash -r python to tell bash to reset the cached location to the python executable.
If hash -r python says too many args then you can use rehash command.
As per the discussion Symbol not found: __PyCodecInfo_GetIncrementalDecoder the issue occurs when Python is updated from Python 2.7.10 to 2.7.11.
If you are using conda package you need to run conda install python=2.7.10 which will solve this problem.
Even downgrading Python to 2.7.10 will also work.
The best solution would be Re-Installing Selenium.
I am running python 2.7.12 with selenium version 2.53.6 and firefox 46.0.1 on an AWS Ubuntu Server 16.04 LTS instance. I've installed pyvirtualdisplay.
When I run this code:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1024, 768))
display.start()
driver = webdriver.Firefox()
I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/anaconda2/lib/python2.7/site- packages/selenium/webdriver/firefox/webdriver.py", line 55, in __init__
self.binary = firefox_binary or capabilities.get("binary", FirefoxBinary())
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 47, in __init__
self._start_cmd = self._get_firefox_start_cmd()
File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 163, in _get_firefox_start_cmd
" Please specify the firefox binary location or install firefox")
RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox
I've tried to add a link to my bash profile
echo export 'PATH="$PATH:/home/firefox"' >> ~/.bashrc
But have not been successful. Any help would be greatly appreciated.
I am using Python Splinter to automate a website and to scrape data from it. When I use the default browser mode which is keeping blank in Browser() it opens firefox and completes the written task but, when I use the headless browser 'zope.testbrowser', I get the following error. What should I need to do here?
Traceback (most recent call last):
File "pysplinter.py", line 4, in <module>
browser = Browser('zope.testbrowser')
File "/usr/local/lib/python2.7/dist-packages/splinter/browser.py", line 62, in Browser
raise DriverNotFoundError("No driver for %s" % driver_name)
splinter.exceptions.DriverNotFoundError: No driver for zope.testbrowser
I don't know if this is still relevant, but will post anyway for the benefit of others.
I faced the same issue and my problem was that mechanize module was not installed.
Fix:
pip install mechanize
However, I faced another issue after this.
Explanation
That's the line of code that is failing in browser.py of splinter, but due to except: pass, it is being silently ignored. If executed manually, the root of the problem can be observed:
>>> from splinter.driver.zopetestbrowser import ZopeTestBrowser
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/rustam/.virtualenvs/python2/lib/python2.7/site-packages/splinter/driver/zopetestbrowser.py", line 19, in <module>
import mechanize
ImportError: No module named mechanize