selenium webdriver BrokenPipeError (timeout issue) - python

I've boiled my code down to the following:
from selenium import webdriver
from time import sleep
b = webdriver.Firefox()
sleep(10)
b.get('http://www.google.com')
This causes a BrokenPipeError on the b.get call. Is this an error with my environment? Something I'm doing wrong, or a bug?
ENV:
Fedora 27 (64bit)
Firefox Quantum 59.0.2 (64bit)
Python 3.6.5
selenium 3.13.0 (via pip)
geckodriver v0.21.0 from github
Update:
I upgraded my workstation and along with that moved to Fedora 28 with a brand new install of Firefox 61, Python 3.6.5, Selenium 3.13.0, and geckodriver 0.21.0 and I have the same problem with the provided script.

You need to specify the path of the webdriver.exe file
first specify path ='path of your webdriver.exe'
path ='path of your webdriver.exe'
and then b = webdriver.Firefox(path)

I use this method to fix this problem and I call it every time there is a risk for timeout. I hope there is a better solution, but this works for me right now.
def refresh(b):
try:
b.refresh()
except BrokenPipeError:
pass

Related

Python Webdriver Manager: Linux Problem on Webdriver Manager for Python

Linux Problem on Webdriver Manager Python
Details:
System - Manjaro Linux
IDE: Visueal Studio Code
Currently, I used the Webdriver Manager tutorial in Python to make my work easier. But IE and Edge are giving me problems.
The Integration:
from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(EdgeChromiumDriverManager().install())
Chromium,Chrome and Firefox to some extent, but there I found a workaround that works thanks to Stackoverflow.
When running Edge on Manjaro Linux I get the following error:
ValueError: There is no such driver by url https://msedgedriver.azureedge.net/91.0.864.70/edgedriver_linux64.zip
[WDM] - ====== WebDriver manager ======
[WDM] - There is no [linux64] edgedriver for browser in cache
[WDM] - Trying to download new driver from https://msedgedriver.azureedge.net/91.0.864.70/edgedriver_linux64.zip
So the question is, is there currently no webdriver for Linux that allows to test IE/Edge on Linux as well?
Is there a workaround?
Version you try to download - missing on the server.
Try change url for download. You can check all verions here.
For example you can install valid driver ( other version ) from this url:
https://msedgewebdriverstorage.blob.core.windows.net/edgewebdriver/92.0.878.0/edgedriver_linux64.zip
Or change code to (specify neeeded and valid version to installation):
from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(EdgeChromiumDriverManager(version="92.0.878.0").install())
Try webdriver-manager>=3.5.1.
Selecting EdgeDriver on Linux and executable permissions were fixed in 3.5.1.
Released to pypi today https://pypi.org/project/webdriver-manager/3.5.1/

Chromium Edge 91 on a Windows 10 crashes

I am trying to run a simple script to open up a google page on Chromium Edge using Python.
What I have so far is
Import selenium
From selenium import webdriver
Path= “..../msedgedriver.exe”
Driver= webdriver.Edge(executable_path=path)
Driver.get(https://google.com)
Got below error:SessionNotCreatedEcception:session not created from tab crashed(Session info:MicrosoftEdge=91.0.864.41)
Tried several things and searched online but no luck yet.Any help will be much appreciated!
There are some problems in the code you provide, I fixed them and tested it, and it works well. My Edge Version is 91.0.864.41 (Official build) (64-bit).
Below is my sample code and you can also try:
import selenium
from selenium import webdriver
path= "D:\\webdriver\\msedgedriver.exe"
driver= webdriver.Edge(executable_path=path)
driver.get("https://www.google.com/")
Please note to modify the path to you owns and use the absolute path of the WebDriver.
I think it may just be a code problem that causes the error.
If the problem persists, can you please provide more information? Such as what version of selenium are you using and what operating system are you using?

Anaconda Selenium issues with webdriver

I have been struggling to figure out why I keep getting errors trying to use selenium. I'm using a local install of anaconda3 on my /home/user unix drive at the company I work for. I already pip installed selenium, seemingly without issue, but when I try the following:
from selenium import webdriver
driver = webdriver.Firefox()
it fails with the following message:
WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
I've tried downloading the most current chromedriver and trying with that, I've tried installing another gecko-driver, I've tried all kinds of things. But nothing is working. I'm happy to provide any amount of additional information, I just want to get this off the ground at some point...
Thank you!
from selenium import webdriver
path = r'C:\yourgeckodriverpath\geckodriver.exe'
driver = webdriver.Firefox(executable_path=path)
Alright, through a combination of the responses to this question, I have figured out what (I think) went wrong. I was using a linux anaconda install on my company's servers, which (I believe) meant my python had no access to a browser driver. The solution was sadly to install anaconda locally, manually download/unzip/install selenium and geckodriver, and then make sure I pass the whole "executable_path=path" parameter to the Firefox method. This didn't work for Chrome for some reason, which I'll assume has something to do with the unchangeable security specifications on my work machine. If any part of this doesn't sound right, feel free to chime in and shed more light on the issue. Thanks!

How can i run casperjs script from python on ubuntu?

I would like to run casperjs from python on zorin os 11. I have researched about that topic but i can not figure it out exactly because there is lack of information as far as i can see. So, how can i do that?
Have you tried the obvious solution? I mean, did you try the following?
import os
os.system('<your ubuntu code>')
For several issues, this 'os' library solve the problem.
Selenium + PhantomJS is your solution (more info http://selenium-python.readthedocs.io/)
from selenium import webdriver
browser = webdriver.PhantomJS()
browser.get("www.yourURL.com")

Selenium: FirefoxProfile exception Can't load the profile

Per this previous question I updated Selenium to version 2.0.1
But now I have another error, even when the profile files exist under /tmp/webdriver-py-profilecopy:
File "/home/sultan/Repository/Django/monitor/app/request.py", line 236, in perform
browser = Firefox(profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 46, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 46, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 44, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 87, in _wait_until_connectable
raise WebDriverException("Can't load the profile. Profile Dir : %s" % self.profile.path)
selenium.common.exceptions.WebDriverException: Can't load the profile. Profile Dir : /tmp/webdriver-py-profilecopy
What is wrong? How can I resolve this issue?
Update:
Selenium team fixed in latest version. For almost all environments the fix is:
pip install -U selenium
Unclear at which version it was fixed (apparently r13122), but certainly by 2.26.0 (current at time of update) it is fixed.
This error means that _wait_until_connectable is timing out, because for some reason, the code cannot connect to the webdriver extension that has been loaded into the firefox.
I have just reported an error to selenium where I am getting this error because I'm trying to use a proxy and only 2 of the 4 configured changes in the profile have been accepted by firefox, so the proxy isn't configured to talk to the extension. Not sure why this is happening...
https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/2061
I had the same issue after upgrading Ubuntu to 12.04.
The issue was on the package side and has been fixed in the latest version of the library. Just update the selenium library. For almost all Python environments this is:
pip install -U selenium
I faced the same problem with FF 32.0 and Selenium selenium-2.42.1-py2.7.egg. Tried to update selenium, but it is already the latest version.
The solution was to downgrade Firefox to version 30. Here is the process:
#Download version 30 for Linux (This is the 64 bit)
wget http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/30.0/linux-x86_64/en-US/firefox-30.0.tar.bz2
tar -xjvf firefox-30.0.tar.bz2
#Remove the old version
sudo rm -rf /opt/firefox*
sudo mv firefox /opt/firefox30.0
#Create a permanent link
sudo ln -sf /opt/firefox30.0/firefox /usr/bin/firefox
This solved all the problems, and this combination works better !
As an extension to Jeff Hoye's answer, a more 'Pythonic' way would be to subclass webdriver.firefox.firefox_profile.FirefoxProfile as follows:
class CygwinFirefoxProfile(FirefoxProfile):
#property
def path(self):
path = self.profile_dir
# Do stuff to the path as described in Jeff Hoye's answer
return path
Then, to create your driver:
driver = webdriver.Firefox(firefox_profile=CygwinFirefoxProfile())
If pip install -U selenium doesn't work (it didn't, in my case), try downgrading your Firefox to a previous version.
I had Firefox 49.0 and downgraded to 45.0 to make sure the version is supported by selenium. It worked perfectly then.
Here's a fast way to downgrade to Firefox 45.0:
sudo apt-get install firefox=45.0.2+build1-0ubuntu1
Hope this helps.
If you are running webdriver from cygwin, the problem is that the path to the profile is still in POSIX format which confuses windows programs. My solution uses cygpath to convert it into Windows format.
in this file/method:
selenium.webdriver.firefox.firefox_binary.launch_browser():
replace:
self._start_from_profile_path(self.profile.path)
with:
from subprocess import Popen, PIPE
proc = Popen(['cygpath','-d',self.profile.path], stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
path = stdout.split('\n', 1)[0]
self._start_from_profile_path(path)
#self._start_from_profile_path(self.profile.path)
Since Python is not even close to my primary programming language, if someone can recommend a more pythonic approach maybe we can push it into the distribution. It sure would be handy if it worked in cygwin right out of the box.
I had the same problem and believed it was the wrong combo of selenium / Firefox. Turned out that my .mozilla/ folder permissions were only accessible to the root user. Doing chmod 770 ~/.mozilla/ did the trick. I would suggest making sure this is not the issue before troubleshooting further.
pip install -U selenium
I had this same issue with Firefox 34.0.5 (Dec 1, 2014) and upgrading Selenium from 2.42.1 to 2.44.0 resolved my issue.
However, I've have since seen this issue again, I think with 2.44.0, and another upgrade fixed it. So I'm wondering if it might be fixed by simply uninstalling and then re-installing. If so, I'm not sure what that would indicate the underlying problem is.
I was using selenium 2.53 and firefox version 55.0. I solved this issue by installing the older version of firefox (46.0.1) since selenium 2.53 will not work for firefox version 47.0 & above.
This is not a proper solution but worked for me, if somebody can improve I would be glad to know. I just run my script as root: sudo python myscript.py. I guess I can solve by changing the profile default file or directory could work.

Categories