无法使用Ghostdriver启动PhantomJS:[WinError 5]访问被拒绝

时间:2015-08-13 01:05:58

标签: python selenium phantomjs ghostdriver

我正在编写使用selenium WebDriver和PhantomJS的python脚本。

我的代码卡在此错误

  

PermissionError:[WinError 5]拒绝访问

我已经浏览了与此错误相关的每个线程并尝试了所有解决方案。所以请不要将其标记为重复。

我以管理员身份运行一切 我也尝试过更改UAC设置。

我的配置:

Python 3.5。 Windows 10(64位)

这是我的python代码。

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")))

这是我得到的错误。


    "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

添加此行后,此问题得到解决。 " driver.set_window_size(1120,550)"。谁能告诉我它为什么会产生拒绝访问错误?

0 个答案:

没有答案