I am using python 3.5, firefox 45 (also tried 49) and selenium 3.0.1
I tried:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
Then I got the error message:
C:\Users\A\AppData\Local\Programs\Python\Python35\python.exe
C:/Users/A/Desktop/car/test.py
Traceback (most recent call last):
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 1220, 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 "C:/Users/A/Desktop/car/test.py", line 4, in <module>
driver = webdriver.Firefox()
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
self.service.start()
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\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 0x0000000000EB8278>>
Traceback (most recent call last):
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Users\A\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
What can I do? Any help is much appreciated!
If you are using firefox ver >47.0.1 you need to have the [geckodriver][1] executable in your system path. For earlier versions you want to turn marionette off. You can to so like this:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities['marionette'] = False
driver = webdriver.Firefox(capabilities=capabilities)
Related
This question already has answers here:
'Webdrivers' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
(22 answers)
Closed 2 years ago.
I'm trying to web scrape reviews from (https://boxes.mysubscriptionaddiction.com/box/boxycharm?ratings=true#review-update-create) but when I run the code:
from selenium import webdriver
chrome_path = r"C:\Users\Sara Jitkresorn\AppData\Local\Programs\Python\Python37\Scripts"
driver = webdriver.Chrome(chrome_path)
driver.get("https://boxes.mysubscriptionaddiction.com/box/boxycharm?ratings=true#review-update-create")
review = driver.find_element_by_class_name("comment-body")
for post in review:
print(post.text)
I got the following error(s). What do I need to do to fix this?
"C:\Users\Sara Jitkresorn\AppData\Local\Programs\Python\Python37\python.exe" "C:/Users/Sara Jitkresorn/PycharmProjects/untitled/venv/SubsAddict.py"
Traceback (most recent call last):
File "C:\Users\Sara Jitkresorn\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\Sara Jitkresorn\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "C:\Users\Sara Jitkresorn\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1155, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Sara Jitkresorn/PycharmProjects/untitled/venv/SubsAddict.py", line 3, in <module>
driver = webdriver.Chrome(chrome_path)
File "C:\Users\Sara Jitkresorn\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\Sara Jitkresorn\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'Scripts' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
You should replace all "\" with "/".
Your chrome path is wrong, you need to find path to chrome executable, it should be stored in Program Files or Program Files x86 Google subfolder.
I am trying to make a function that refreshes any page when given the URL. But the program won't run. What am I doing wrong? This is my code:
from selenium import webdriver
import time
def page_refresh(url):
driver = webdriver.Firefox()
driver.get(url)
x = 0
while x <= 5:
time.localtime(10)
driver.refresh(url)
driver.close
page_refresh('https://www.wikipedia.org/')
This is what I get:
Traceback (most recent call last):
File "C:\Users\100453649\PycharmProjects\AutoRefresher\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\100453649\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\100453649\AppData\Local\Programs\Python\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 "C:/Users/100453649/PycharmProjects/AutoRefresher/Main.py", line 13, in <module>
page_refresh('https://www.wikipedia.org/')
File "C:/Users/100453649/PycharmProjects/AutoRefresher/Main.py", line 5, in page_refresh
driver = webdriver.Firefox()
File "C:\Users\100453649\PycharmProjects\AutoRefresher\venv\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 152, in __init__
self.service.start()
File "C:\Users\100453649\PycharmProjects\AutoRefresher\venv\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: 'geckodriver' executable needs to be in PATH.
Your Exception clearly says that
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Solution:
Add gecko driver path:
Example:
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
driver.get(url)
I need to launch Firefox with Browsec add-on. I've written some code, but get an error:
from selenium import webdriver
url = input("Enter url to scrape from: ")
profile = webdriver.FirefoxProfile()
profile.add_extension('/home/myusername/.mozilla/firefox/b5qyukpg.default/extensions/browsec#browsec.com.xpi')
browser = webdriver.Firefox()
browser.get(url)
What i get is:
Traceback (most recent call last):
File "scraper.py", line 7, in <module>
profile.add_extension('/home/myusername/.mozilla/firefox/b5qyukpg.default/extensions/browsec#browsec.com.xpi')
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 95, in add_extension
self._install_extension(extension)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 274, in _install_extension
addon_details = self._addon_details(addon)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 351, in _addon_details
raise AddonFormatError(str(e), sys.exc_info()[2])
selenium.webdriver.firefox.firefox_profile.AddonFormatError: ("[Errno 2] No such file or directory: '/tmp/tmpd7nyxubj.browsec#browsec.com.xpi/install.rdf'", <traceback object at 0x7f23f786eb08>)
How can i fix that error?
I am attempting to run a simple program on an Ubuntu 16.04 instance using Python 3.5. The program is below;
from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.PhantomJS("p/phantomjs")
driver.get("http://www.bbc.co.uk")
s = BeautifulSoup(driver.page_source, "lxml")
print(s.findAll("a"))
try:
driver.close()
except AttributeError:
pass
All the modules are installed correctly. However, when I run the program, I receive the following errors:
Traceback (most recent call last):
File "t.py", line 4, in <module>
driver = webdriver.PhantomJS("p/phantomjs")
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 52, in __init__
self.service.start()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 64, 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)
OSError: [Errno 8] Exec format error
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.phantomjs.service.Service object at 0x7fb05cd964a8>>
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 163, in __del__
self.stop()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
It seems as though it is an issue with Selenium rather than with PhantomJS. However, I have no idea how to make the program work properly.
In other questions similar to this, the issue seems to be with closing the headless instance. However, this error is received as soon as I try to instantiate PhantomJS.
How can this be fixed?
If p folder (as you've mentioned) located in the same directory as your script, then you might need to start your code with something like
from bs4 import BeautifulSoup
from selenium import webdriver
import os
path_to_phantom_js = os.path.dirname(__file__) + '/p/phantomjs'
driver = webdriver.PhantomJS(path_to_phantom_js)
P.S. If it not works, tell me output of print(path_to_phantom_js)
Selenium version: 2.53.6
Firefox version: 47.0.1
Chrome version: 51.0.2704.106 m
Now if I want to use them like that:
from selenium import webdriver
driver = webdriver.Firefox()
driver2 = webdriver.Chrome()
i get an error:
FileNotFoundError: [WinError 2]
i even checked the manual twice that its the correct way to code it.
So why cant it find the browsers even though everything is updated to latest version?
Firefox and chrome work fine if I use them as person.
edit:
can provide error code in comment so here it is, (srry some parts are in german, as it is the main language istalled on my pc):
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
driver = webdriver.Firefox()
File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
self.binary, timeout)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 67, in launch_browser
self._start_from_profile_path(self.profile.path)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 90, in _start_from_profile_path
env=self._firefox_env)
File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden
and for Chrome its:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
driver2 = webdriver.Chrome()
File "C:\Program Files (x86)\Python35-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Program Files (x86)\Python35-32\lib\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: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
the wierd thing is i did include it in path enivornment variables. I can type in 'chromedriver' in the cmd and it finds it.... so python should too.
1 more mistake:
doing last thing says some wierd stuff about: only local connetctions are allowed.
I'm not sure about running two drivers at the same time, but for the chrome part at least you may need to point it to a chrome driver (which you can download from https://sites.google.com/a/chromium.org/chromedriver/downloads
import time
from selenium import webdriver
#driver = webdriver.Chrome('..\..\..\chromedriver.exe') # Optional argument, if not specified will search path that script is running in.
driver = webdriver.Chrome('E:\AutomatedTesting\PyTestFramework\Automation\selenium\AdditionalDrivers\chromedriver.exe') #this is my path, I haven't worked out how to make the path relative to the script yet
driver.get('http://www.google.com/xhtml');
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()