Selenium test execute - python

Hi in Pycharm I have installed Selenium in virtualenv. I try execute
from selenium import webdriver
#from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
#binary = FirefoxBinary('/webdriver/firefox')
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django ' in browser.title
but I have error
(django_env)darek#Toshiba:~/PycharmProjects/Django$ python
functional_tests.py Traceback (most recent call last): File
"functional_tests.py", line 5, in
browser = webdriver.Firefox() File "/home/darek/.virtualenvs/django_env/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py",
line 140, in init
self.service.start() File "/home/darek/.virtualenvs/django_env/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
line 74, in start
stdout=self.log_file, stderr=self.log_file) File "/usr/lib/python3.5/subprocess.py", line 947, in init
restore_signals, start_new_session) File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg) NotADirectoryError: [Errno 20] Not a directory Exception ignored in: > Traceback (most recent call last): File
"/home/darek/.virtualenvs/django_env/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
line 173, in del
self.stop() File "/home/darek/.virtualenvs/django_env/lib/python3.5/site-packages/selenium/webdriver/common/service.py",
line 145, in stop
if self.process is None: AttributeError: 'Service' object has no attribute 'process'
I download geckodriver ver. 11 and add to variable path and add in bashrc
export PYTHONPATH=${PYTHONPATH}:/usr/bin export
WORKON_HOME=$HOME/.virtualenvs export PROJECT_HOME=$HOME/MyProject
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 source
/usr/local/bin/virtualenvwrapper.sh
source django_env/bin/activate export
PATH=$PATH:/home/darek/webdriver/firefox/geckodriver export
PATH=$PATH:/home/darek/webdriver/firefox/wires
what can I do more?

Related

Exec format error - while executing sample code from selenium [duplicate]

from selenium import webdriver
browser = webdriver.Firefox(executable_path="/usr/bin/geckodriver")
browser.get('http://www.ubuntu.com/')
The entire stack trace looks like:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 160, in __init__
self.service.start()
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: 'geckodriver'
my path to geckodriver is:
/usr/bin/geckodriver
And selenium is in:
selenium in /usr/local/lib/python3.6/dist-packages (3.12.0)
Thanks in advance!
You have most probably installed a version of geckodriver that is meant for a different OS/platform! get the correct version from https://github.com/mozilla/geckodriver/releases and replace the one you have.
Use this command to install the latest chrome driver which supports selenium:
sudo apt-get install chromium-chromedriver

How can I run chromedriver on repl.it

I basically want to use selenium on repl.it, but don't know how to do that. I tried installing chromedriver into repl.it but I still get this error:
Traceback (most recent call last):
File "/home/runner/dictionaryBot/venv/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 71, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/nix/store/p21fdyxqb3yqflpim7g8s1mymgpnqiv7-python3-3.8.12/lib/python3.8/subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/nix/store/p21fdyxqb3yqflpim7g8s1mymgpnqiv7-python3-3.8.12/lib/python3.8/subprocess.py", line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 3, in <module>
driver = webdriver.Chrome()
File "/home/runner/dictionaryBot/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/home/runner/dictionaryBot/venv/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 90, in __init__
self.service.start()
File "/home/runner/dictionaryBot/venv/lib/python3.8/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://chromedriver.chromium.org/home
This is my code
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://youtube.com")
Try forking this Repl, it has working Selenium that you can use: Advanced Selenium Options

cannot run webdriver.Firefox from selenium webdriver

I am having trouble using Selenium
I am using Python 3.6, on a Windows 7 machine at my workplace. Firefox is 61.0.1 (64-bit)
Python is loaded in C:\Program Files (x86)\Python36-32
My work is in H:\PythonPrograms
I have successfully installed selenium:
C:\Windows\System32>pip install selenium
Requirement already satisfied: selenium in c:\program files (x86)\python36-32\lib\site-packages (3.13.0)
Per other advice found here, I downloaded geckodriver.exe and placed it both into C:\Program Files (x86)\Python36-32 and H:\PythonPrograms.
My path includes: C:\Program Files (x86)\Python36-32\Scripts\;C:\Program Files (x86)\Python36-32\;H:\PythonPrograms
I am following the steps on "Automate the Boring Stuff with Python" (Al Sweigart) p. 257
>>> from selenium import webdriver
>>> browser = webdriver.Firefox()
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
browser = webdriver.Firefox()
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 159, in __init__
log_path=log_path)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\service.py", line 44, in __init__
log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
PermissionError: [Errno 13] Permission denied: 'geckodriver.log'
>>> browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 159, in __init__
log_path=log_path)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\service.py", line 44, in __init__
log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
PermissionError: [Errno 13] Permission denied: 'geckodriver.log'
>>>
(IT's not the permissaion on geckodriver.log. This even happens when I delete that file and try again. Also I checked permissions: )
When I run Python as administrator from a new Python session:
>>> from selenium import webdriver
>>> browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
Traceback (most recent call last):
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
browser = webdriver.Firefox(executable_path=r'H:\PythonPrograms')
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
self.service.start()
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'PythonPrograms' executable needs to be in PATH.
I don't understand what is happening between me running Python normally vs running as administrator. Whichever, neither way gives me expected output.
added new run example by changing the executable_path to include the program name and remove the "r" qualifier. Here are the new results:
>>> from selenium import webdriver
>>> browser = webdriver.Firefox(executable_path='H:\PythonPrograms\geckodriver.exe')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
browser = webdriver.Firefox(executable_path='H:\PythonPrograms\geckodriver.exe')
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
keep_alive=True)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
>>>
Instead of using regular expression try to give exact path with exe file name
browser = webdriver.Firefox(executable_path='H:\PythonPrograms\yourexenamehere.exe')

using splinter to navigate webpages, cannot get Browser

At first I tried the standard "from splinter import Browser" but I got the follwoing error:
from splinter import browser
ImportError: No module named 'splinter'
now, I installed it via git, and ensured the dist-packages was created. I've tried python 2.7 and 3. Now lately, I'm using the following:
#!/usr/bin/env python2 (get errors when changing to 3 as well)
import splinter
def navigate_to(web_page, how_long):
b = splinter.Browser()
b.visit(web_page)
which gives the following
Traceback (most recent call last):
File "./hw", line 30, in <module>
navigate_to(platform_int, 60)
File "./hw", line 23, in navigate_to
b = splinter.Browser()
File "build/bdist.linux-x86_64/egg/splinter/browser.py", line 63, in Browser
File "build/bdist.linux-x86_64/egg/splinter/driver/webdriver/firefox.py", line 49, in __init__
File "/usr/local/lib/python2.7/dist-packages/selenium-3.3.1-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 145, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium-3.3.1-py2.7.egg/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python2.7/subprocess.py", line 390, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1024, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
Help?!

selenium: unable to access geckodriver

I dowloaded the latest versions of both selenium and geckodriver.
I did the following:
bash
cp Downloads/geckodriver /usr/local/bin/
PATH=$PATH:/usr/local/bin/geckodriver
python
from selenium import webdriver
browser = webdriver.Firefox()
error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/chris/anaconda/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__
self.service.start()
File "/Users/chris/anaconda/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/Users/chris/anaconda/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/Users/chris/anaconda/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
UPDATE
I did the same thing with chrome web driver:
browser = webdriver.Chrome()
error
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Mac OS X 10.12.3 x86_64)
Is this something to do with specifying the path?? Really confused as I am inexperienced with bash

Categories

Resources