chrome driver install with selenium - python

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.

Related

Errror with using Selenium Webdriver with chrome

from bs4 import BeautifulSoup, SoupStrainer
from selenium import webdriver
from selenium.webdriver import chrome
from selenium.webdriver.chrome.options import Options
url = 'https://...'
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument("--headless")
driver = webdriver.Chrome('path')
driver.get(url)
Error:
Traceback (most recent call last):
File "", line 20, in <module>
driver.get(EPL_url)
File "", line 333, in get
self.execute(Command.GET, {'EPL_url': url})
File "", line 321, in execute
self.error_handler.check_response(response)
File "", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown command: unknown command: session/9df33bd6f0e57084300c81738cf6c2d5/EPL_url
I have tried to look at all the potential errors around this and have found nothing. The annoying things is, the "driver.get()" function was working perfectly earlier. It only seemed to have been disrupted after I had changed the variable name of the URL. I seriously do not know what to do and need to get this code back up and running.
Please help me with the above error so I can rectify this!! It would be much appreciated.
This issue can be because of the path of the chrome driver.
Here's a simpler solution: install the python-chrome drive package, import it in your script, and it's done.
Step by step:
pip install chromedriver-binary
import the package
from selenium import webdriver
import chromedriver_binary # Adds chromedriver binary to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")
Reference: https://pypi.org/project/chromedriver-binary/

selenium webdriver.firefox() Error [duplicate]

This question already has answers here:
Selenium using Python - Geckodriver executable needs to be in PATH
(36 answers)
Closed 5 years ago.
I am trying to use selenium to start google chrome but i get an error
here is my code:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django' in browser.title
here is the error:
Traceback (most recent call last):
File "functional_tests.py", line 5, in <module>
browser = webdriver.Firefox(firefox_binary=binary)
File "C:\Python27\lib\site-
packages\selenium\webdriver\firefox\webdriver.py", line 140, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x03D51FD0>> ignored
any help with that?
Make sure you have latest geckodriver and firefox is installed in default dir.
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH leads to geckodriver issue, can be solved by providing the path to the geckodriver. Possible reason, geckdriver location is not added to the PATH.
binary = FirefoxBinary('path')
browser = webdriver.Firefox(firefox_binary=binary)
Exception AttributeError: "'Service' object has no attribute 'process'" looks like to me your firefox is installed in custom location. Please confirm.

Splinter: DriverNotFoundError for zope.testbrowser

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

Permission Denied when load Firefox Extension in WebDriver

I'm creating a python script with selenium webdriver. I need to use an extension in firefox, but when I test with a little script, the script produces an error like this:
Traceback (most recent call last):
File "C:\Users\User\Desktop\Bot\Mania.py", line 8, in <module>
firefoxProfile.add_extension(elem)
File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py", line 93, in add_extension
self._install_extension(extension)
File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py", line 264, in _install_extension
with open(os.path.join(tmpdir, name), 'wb') as f:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\User\\AppData\\Local\\Temp\\tmpzq3rmztk.firebug-2.0.11-fx.xpi\\content/firebug/'
[Finished in 0.4s with exit code 1]
The sample code is it:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os
firefoxProfile = FirefoxProfile()
elem = "quickjava-2.0.6-fx.xpi"
firefoxProfile.add_extension(elem)
firefoxProfile.set_preference("thatoneguydotnet.QuickJava.startupStatus.CSS", 2)
driver = webdriver.Firefox(firefoxProfile)
driver.get('http://www.google.cl')
PS: The add-on is in the same folder that the script. I tested with full path but it doesn't work too.
You need to provide an absolute path to the extension:
firefoxProfile.add_extension("/absolute/path/to/the/extension")

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