I am new to Splinter but I have used python few times. So I was hoping to automate a website using splinter. But I get the "ImportError: cannot import name Browser" error when I execute it.
Here is my code.
from splinter import Browser
browser = Browser()
browser.visit('http://google.com')
browser.fill('q', 'splinter - python acceptance testing for web applications')
browser.find_by_name('btnG').click()
if browser.is_text_present('splinter.readthedocs.org'):
print "Yes, the official website was found!"
else:
print "No, it wasn't found... We need to improve our SEO techniques"
browser.quit()
In terminal this is what I get.
Traceback (most recent call last):
File "splinter.py", line 3, in <module>
from splinter import Browser
File "/var/www/project/splinter.py", line 3, in <module>
from splinter import Browser
ImportError: cannot import name Browser
How can I run this program without any error? I have referred solutions for similar issues like deleting splinter.pyc but it didn't help me.
You have a local file named splinter.py
, which is shadowing the library splinter
as can be seen from the traceback -
Traceback (most recent call last):
File "splinter.py", line 3, in
from splinter import Browser
Rename that file , you should not name your python files or packages in a way that would shadow/mask the libraries.