Does selenium python bindings require firefox - python

Hi I just downloaded and installed selenium but, I can't figure out how to get it working I am using the following example as a test....
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox() #this is where I hit the error
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("selenium")
elem.send_keys(Keys.RETURN)
assert "Google" in driver.title
driver.close()
I do not have firefox installed on my computer is this why it is giving me an error?
this is the error output I get when I try and run it
Traceback (most recent call last):
File "C:/Python27/test/helloworld.py", line 4, in <module>
driver = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 60, in __init__
self.binary, timeout),
File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 60, in launch_browser
self._start_from_profile_path(self.profile.path)
File "C:\Python27\lib\site-packages\selenium-2.35.0-py2.7.egg\selenium\webdriver\firefox\firefox_binary.py", line 83, in _start_from_profile_path
env=self._firefox_env).communicate()
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 893, in _execute_child
startupinfo)
WindowsError: [Error 87] The parameter is incorrect

Following line starts Firefox browser so yes, it requires installed Firefox.
driver = webdriver.Firefox()
If you don't have Firefox installed you can use different browser instead:
webdriver.Opera
webdriver.Ie
webdriver.Chrome
...
See
help(webdriver)

Related

I facing a problem in set up selenium in virtual studio code for python

from selenium import webdriver
chromedriver_location = "/Users/Sony/Desktop/XUAN/Python/chromedriver_win32/chromedriver"
driver = webdriver.Chrome()
driver.get('https://sapsnkra.moe.gov.my/ibubapa2/')
input(" ")
PS C:\Users\Sony\Desktop\XUAN\Python> python -u "c:\Users\Sony\Desktop\XUAN\Python\Python Project\tempCodeRunnerFile.py"
Traceback (most recent call last):
File "C:\Users\Sony\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\common\service.py", line 71, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 951, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
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 "c:\Users\Sony\Desktop\XUAN\Python\Python Project\tempCodeRunnerFile.py", line 3, in
driver = webdriver.Chrome()
File "C:\Users\Sony\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in init
super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Users\Sony\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\selenium\webdriver\chromium\webdriver.py", line 90, in init
self.service.start()
File "C:\Users\Sony\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\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
You can actually use webdriver-manager to automatically manage your chromedriver version.
You can use it like this:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://sapsnkra.moe.gov.my/ibubapa2/')
input(" ")

Cant run Selenium on Ubuntu with Python

I cant run or install selenium on Ubuntu 18.04.3 ...
I followed this tutorial: https://medium.com/#hoppy/how-to-test-or-scrape-javascript-rendered-websites-with-python-selenium-a-beginner-step-by-c137892216aa also with the digitalocean setup.
I tried different things...
I installed the geckodriver in /var/bin
in /var/local/bin
added both to PATH
tried with a path in the code and without
tried with firefox (preferred) ...
nothing helps
This Code:
import time
from selenium import webdriver
driver = webdriver.Chrome('/usr/bin/chromedriver') # Optional argument, if not specified will search path.
driver.get('http://www.google.com/');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
Ends up with:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
selenium.common.exceptions.WebDriverException:: command not found
(venv) root#EtherScrape:/var/test# python /var/test/server_test.py Traceback (most recent call last):
File "/var/test/server_test.py", line 5, in <module>
driver = webdriver.Chrome('/usr/bin/chromedriver') # Optional argument, if not specified will search path.
File "/var/venv/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/var/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/var/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/var/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/var/venv/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=83.0.4103.61 (94f915a8d7c408b09cc7352161ad592299f384d2-refs/branch-heads/4103#{#561}),platform=Linux 4.15.0-66-generic x86_64)
This Code:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(firefox_options=options)
With that error:
Traceback (most recent call last):
File "/var/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver': 'geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/test/server_test.py", line 6, in <module>
driver = webdriver.Firefox(firefox_options=options)
File "/var/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/var/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7ff3109ced68>>
Traceback (most recent call last):
File "/var/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 163, in __del__
self.stop()
File "/var/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Please help.
Tried many solutions so far but no one worked out...
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model
Works for me at the chrome driver.

Python Selenium getting started error

I have updated to Selenium 3. I have set gecko in PATH but continue to get the error. Firefox starts up but then no action for a few moments and Firefox closes (i assume a time out).Any incite would be greatly appreciated!
Traceback (most recent call last):
File "C:\Users\Paul\Documents\python selenium\python_org_search.py", line 4, in
driver = webdriver.Firefox()
File "C:\Python27\lib\selenium\webdriver\firefox\webdriver.py", line 78, in init
self.binary, timeout)
File "C:\Python27\lib\selenium\webdriver\firefox\extension_connection.py", line 49, in init
self.binary.launch_browser(self.profile)
File "C:\Python27\lib\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable()
File "C:\Python27\lib\selenium\webdriver\firefox\firefox_binary.py", line 106, in _wait_until_connectable
% (self.profile.path))
WebDriverException: Message: Can't load the profile. Profile Dir: c:\users\paul\appdata\local\temp\tmphptyx9 If you specified a log_file in the FirefoxBinary constructor, check it for details.
EDIT:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

Selenium python website login

I was trying over the past few hours , without success , to make webdriver.Firefox() run properly. I reinstalled geckodriver and verified it was added to the path , i tried to use FirefoxBinary but it didn't help.
I could not find any solution , and I am not sure how to fix this , I would appreciate your help.
This is the code :
#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import time
browser = webdriver.Firefox()
browser.get("https://testweb.com")
time.sleep(10)
username = browser.find_element_by_id("extpatid")
password = browser.find_element_by_id("extpatpw")
username.send_keys("username")
password.send_keys("password")
login_attempt = browser.find_element_by_xpath("//*[#type='submit']")
login_attempt.submit()
Below are the exceptions received when I tried to execute the script :
Traceback (most recent call last):
File "./braude.py", line 7, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/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 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
Python version :
# /usr/bin/python -V
Python 2.7.12+
I'm not sure why you have this line:
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
but it's completely unnecessary and likely related to your ultimate problem - a wrong version of the Firefox webdriver module.
Try Chrome and see how it reacts with that.

Selenium with PhantomJS gives KeyError: 'sessionId' when trying to start a session

I'm trying to use Selenium (2.47.3) with PhantomJS (2.0.0) on Mac, but receive the error in the title. Python is 3.5.0.
Traceback (most recent call last):
File "/Users/QuickSilver/Desktop/autocrawlerfinal.py", line 31, in <module>
driver = webdriver.PhantomJS('/Users/QuickSilver/Desktop/crawler/phantomjs-2.0.0-macosx/bin/phantomjs', port=631)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 56, in __init__
desired_capabilities=desired_capabilities)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 87, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 143, in start_session
self.session_id = response['sessionId']
KeyError: 'sessionId'
The minimal code to reproduce is
from selenium import webdriver
driver = webdriver.PhantomJS('/Users/QuickSilver/Desktop/crawler/phantomjs-2.0.0-macosx/bin/phantomjs', port=631)
The only mention of this error online mentions system proxy, but there is none and localhost is added to the exceptions anyway. What could be causing this?

Categories