Splinter: DriverNotFoundError for zope.testbrowser - python

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

Related

Selenium, chromedriver and python difficulties

I have this written down in my code but this keeps happening and I'm unsure what to do. I followed this video but don't know where to go as I followed the steps
https://www.youtube.com/watch?v=7R5n0sNSza8
from selenium import webdriver
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'

Import Error Symbol not found: __PySlice_AdjustIndices

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.

SublimeREPL on Sublime Text 3 not importing Python 2.7 modules

I have been trying to configure SublimeText 3 to run SublimeREPL, setting everything so it runs as IDLE, or PyCharm IDE, but, after trying different options I checked in SO, it keeps returning:
>>> import pandas
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named pandas
>>> import os
>>> os.environ['PYTHONPATH']
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'PYTHONPATH'
I have tried editing the SublimeREPL.sublime-settings file with the default extend path file you can see at the FAQ site of SublimeREPL, but still does not work.
Does anyone know how this could be solved?
I don't know if this is the problem for you, but I was getting the exact same error and learned that by opening sublime text from the command line (e.g. 'subl .' to open the directory, once you have that shortcut set up) you get one PATH- and if you open sublime text from Spotlight Search you get another PATH. Try opening sublime text from the command line once you've confirmed you can import pandas in an interactive command line session and hopefully it will work.

unable to import browser from mechanize

I am using mechanize for the first time. If I type the line from mechanize import Browserin python shell (interpreter) it doesn't give any error but when run the same code as a part of a .py file it gives the following error:
Traceback (most recent call last):
File "/home/namit/Codes/BS4/mechanize.py", line 1, in <module>
import mechanize
File "/home/namit/Codes/BS4/mechanize.py", line 4, in <module>
mech = mechanize.Browser()
AttributeError: 'module' object has no attribute 'Browser'
Change your filename from mechanize.py. Python is importing your file as the module, instead of importing the mechanize library.
Rename your filename to something other than mechanize.py
Giving files names same as that of the modules imported causes the file to be imported instead of the intended module.

trying to set path for selenium / phantomjs on win7

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.

Categories

Resources