0

Installed Selenium on my IntellIJ. I am trying to complete exercise 2.1 at http://selenium-python.readthedocs.io/getting-started.html .

This is my code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome("C:\Python27\Scripts/")
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_class_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

Which produces the following error:

Traceback (most recent call last):
  File "B:\Program Files (x86)\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "B:\Program Files (x86)\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "B:\Program Files (x86)\lib\subprocess.py", line 990, 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 "B:/Alexander/Documents/PythonPrograms/Selenium/Test.py", line 3, in <module>
    driver = webdriver.Chrome("C:\Python27\Scripts/")
  File "B:\Program Files (x86)\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "B:\Program Files (x86)\lib\site-packages\selenium\webdriver\common\service.py", line 86, in start
    os.path.basename(self.path), self.start_error_message)
**selenium.common.exceptions.WebDriverException: Message: '' executable may have wrong permissions**. Please see https://sites.google.com/a/chromium.org/chromedriver/home
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
primeru333
  • 11
  • 1
  • 3
  • I do not see any question here. – lordrhodos Jun 10 '17 at 19:38
  • I am getting "selenium.common.exceptions.WebDriverException: Message: '' executable may have wrong permissions" and I dont know how about to fix it. – primeru333 Jun 10 '17 at 20:24
  • (OT) "B:\Program Files (x86)" ?! I sense someone who was born too late to see the floppy disk era... – ivan_pozdeev Jun 10 '17 at 20:28
  • Possible duplicate of [Python Selenium Chrome Webdriver](https://stackoverflow.com/questions/42478591/python-selenium-chrome-webdriver) – ivan_pozdeev Jun 11 '17 at 09:14
  • No intent to be condescending. Just was amused by a "total lack of respect for letters A: and B:" ) The fact that ppl born after 2000 are now getting old enough to program is just a fact of life - regardless of whether you're one or not. – ivan_pozdeev Jun 11 '17 at 09:44

1 Answers1

0

The code that triggers the exception looks like this:

def start(self):
<...>
    try:
        cmd = [self.path]
        cmd.extend(self.command_line_args())
        self.process = subprocess.Popen(cmd, <...>)
<...>
    except OSError as err:
<...>
        elif err.errno == errno.EACCES:
            raise WebDriverException(
                "'%s' executable may have wrong permissions. %s" % (
                    os.path.basename(self.path), self.start_error_message)

As you can see, '' in the error message means that os.path.basename(self.path) is empty. And the message being formulated like this suggests that the code's author didn't intend it to be empty.

Let's see what it's initialized from. Searching the repo for references brings us to py/selenium/webdriver/common/service.py:37:

class Service:

    def __init__(self, executable, port=0, log_file=DEVNULL, env=None, start_error_message=""):
        self.path = executable
    <...>

Which means, self.path is the first argument you passed to webdriver.Chrome, i.e. "C:\Python27\Scripts/". Since it's then passed to subprocess as the program to execute, it should be a path to an executable file, not to a directory. Judging by other results in the search above, the path to Chrome executable. In the example, a Firefox driver is started without arguments, but as the search results show, it seems to have autodetection from profile or something.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152