Skip to content

Commit b2f6073

Browse files
stvsmthandreastt
authored andcommitted
py: improve OSError exception on starting chromedriver
Fixes issue 8497 on googlecode. Catching too-broad an exception squashes esoteric bugs like 8498 on googlecode (too many open files). Signed-off-by: Andreas Tolfsen <[email protected]>
1 parent 2051ad9 commit b2f6073

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

Diff for: py/selenium/webdriver/chrome/service.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919
import os
20+
import errno
2021
import subprocess
2122
from subprocess import PIPE
2223
import time
@@ -54,22 +55,32 @@ def start(self):
5455
Starts the ChromeDriver Service.
5556
5657
:Exceptions:
57-
- WebDriverException : Raised either when it can't start the service
58-
or when it can't connect to the service
58+
- WebDriverException : Raised either when it cannot find the
59+
executable, when it does not have permissions for the
60+
executable, or when it cannot connect to the service.
61+
- Possibly other Exceptions in rare circumstances (OSError, etc).
5962
"""
6063
env = self.env or os.environ
6164
try:
6265
self.process = subprocess.Popen([
6366
self.path,
6467
"--port=%d" % self.port] +
6568
self.service_args, env=env, stdout=PIPE, stderr=PIPE)
66-
except:
67-
raise WebDriverException(
68-
"'" + os.path.basename(self.path) + "' executable needs to be \
69-
available in the path. Please look at \
70-
http://docs.seleniumhq.org/download/#thirdPartyDrivers \
71-
and read up at \
72-
https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver")
69+
except OSError as err:
70+
docs_msg = "Please see " \
71+
"https://sites.google.com/a/chromium.org/chromedriver/home"
72+
if err.errno == errno.ENOENT:
73+
raise WebDriverException(
74+
"'%s' executable needs to be in PATH. %s" % (
75+
os.path.basename(self.path), docs_msg)
76+
)
77+
elif err.errno == errno.EACCES:
78+
raise WebDriverException(
79+
"'%s' executable may have wrong permissions. %s" % (
80+
os.path.basename(self.path), docs_msg)
81+
)
82+
else:
83+
raise
7384
count = 0
7485
while not utils.is_connectable(self.port):
7586
count += 1

0 commit comments

Comments
 (0)