1

I am writing python script which is using selenium WebDriver and PhantomJS.

My code is stuck at this error

PermissionError: [WinError 5] Access is denied

I have gone through every single threads related to this error and tried all solutions. So please do not mark it as duplicate.

I am running everything as administrator.
I tried changing UAC setting as well.

My configuration:

Python 3.5. Windows 10 (64 bit)

Here is my python code.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from twilio.rest import TwilioRestClient

driver = webdriver.PhantomJS(executable_path='C:/Users/USER/Python/Demo');
driver.get("https://49erexpress.uncc.edu/cp/home/displaylogin") # Open homepage

driver.find_element(By.CLASS_NAME, "login_username").send_keys("user");
driver.find_element(By.CLASS_NAME, "login_password").send_keys("****");
driver.execute_script("return login()");
driver.find_element_by_link_text('Class Schedule').click();  # Click on class schedule

driver.switch_to_default_content()
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it("content"))
#driver.switch_to.frame("content")

wait = WebDriverWait(driver, 20)
#link = wait.until(EC.presence_of_element_located((By.LINK_TEXT, 'Add/Drop/Withdraw Classes')))  # Click on Add/Drop/Withdraw Classes
link = wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/div[3]/table[1]/tbody/tr[1]/td[2]/a[text()='Add/Drop/Withdraw Classes']"))) # Click on Add/Drop/Withdraw Classes
link.click()

wait = WebDriverWait(driver, 20)
driver.switch_to_default_content()
driver.switch_to.frame("content")

link = wait.until(EC.presence_of_element_located((By.XPATH, "//input[@value='Submit']")))  # Click on Submit button
link.click()

wait = WebDriverWait(driver, 20)
driver.switch_to_default_content()
driver.switch_to.frame("content")

driver.find_element(By.ID, "crn_id1").send_keys("16595");
link = wait.until(EC.presence_of_element_located((By.XPATH, "//input[@value='Submit Changes']")))  # Click on submit changes
link.click()

wait = WebDriverWait(driver, 20)
driver.switch_to_default_content()
driver.switch_to.frame("content")

link = wait.until(EC.presence_of_element_located((By.XPATH,"//td[contains(text(),'16595')]/preceding-sibling::td")))

And here is the error that I am getting.


    "C:\Program Files\Python 3.5\python.exe" C:/Users/USER/Python/Demo/main_update2.py
    Traceback (most recent call last):
      File "C:\Program Files\Python 3.5\lib\site-packages\selenium\webdriver\phantomjs\service.py", line 73, in start
        stdout=self._log, stderr=self._log)
      File "C:\Program Files\Python 3.5\lib\subprocess.py", line 855, in __init__
        restore_signals, start_new_session)
      File "C:\Program Files\Python 3.5\lib\subprocess.py", line 1125, 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/USER/Python/Demo/main_update2.py", line 10, in 
        driver = webdriver.PhantomJS(executable_path='C:/Users/USER/Python/Demo');
      File "C:\Program Files\Python 3.5\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 51, in __init__
        self.service.start()
      File "C:\Program Files\Python 3.5\lib\site-packages\selenium\webdriver\phantomjs\service.py", line 76, in start
        raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e)
    selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghostdriver: [WinError 5] Access is denied


    Process finished with exit code 1

This issue got resolved when I added this line. "driver.set_window_size(1120, 550)". Can anyone tell me why it was generating access denied error?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222

0 Answers0