Unable to start PhantomJS with Ghostdriver: [WinError 5] Access is denied - python

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?

Related

Selenium Automation Chrome browser opens and closes with error mesage

Good Day Ahead.
After searching numerious posts in Stackoverflow, I tried to write and implement the automation using selenium and python programming.
I tried my first code as below and i am getting error.
My browser opens and closes very fast. It throws error in the output.
Code:-
import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
s=Service(ChromeDriverManager().install())
chrome_driver = webdriver.Chrome(service=s)
browser = webdriver.Chrome("/home/halovivek/Documents/Automation/selenium_driver/")
browser.implicitly_wait(5)
browser.get("https://www.google.com")
#browser.get("https://kite.zerodha.com/")
browser.implicitly_wait(5)
Error:-
/home/halovivek/PycharmProjects/yearcoding/venv/bin/python /home/halovivek/PycharmProjects/yearcoding/06092022_selenium1.py
/home/halovivek/PycharmProjects/yearcoding/06092022_selenium1.py:9: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
browser = webdriver.Chrome("/home/halovivek/Documents/Automation/selenium_driver/")
Traceback (most recent call last):
File "/home/halovivek/PycharmProjects/yearcoding/venv/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 71, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/usr/lib/python3.10/subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.10/subprocess.py", line 1842, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/home/halovivek/Documents/Automation/selenium_driver/'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/halovivek/PycharmProjects/yearcoding/06092022_selenium1.py", line 9, in <module>
browser = webdriver.Chrome("/home/halovivek/Documents/Automation/selenium_driver/")
File "/home/halovivek/PycharmProjects/yearcoding/venv/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/home/halovivek/PycharmProjects/yearcoding/venv/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 89, in __init__
self.service.start()
File "/home/halovivek/PycharmProjects/yearcoding/venv/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 86, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: '' executable may have wrong permissions. Please see https://chromedriver.chromium.org/home
Process finished with exit code 1
Please help me
I don't understand why this line comes
browser = webdriver.Chrome("/home/halovivek/Documents/Automation/selenium_driver/")
After you already properly created webdriver instance with
s=Service(ChromeDriverManager().install())
chrome_driver = webdriver.Chrome(service=s)
?
Looks like your code should be as following:
import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
s=Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
driver.implicitly_wait(5)
driver.get("https://www.google.com")
UPD
To make your browser stay opened add "detach", True option, as following:
import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
s=Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s, chrome_options=chrome_options)
driver.implicitly_wait(5)
driver.get("https://www.google.com")

Why isn't my chrome profile responding to driver commands?

from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 4")
driver = webdriver.Chrome
('C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe', options=options)
Successfully opens my profile, it won't search for this website nor click any xpaths.
My chrome driver is located at C:\\webdrivers\\chromedriver.exe but when I use that instead of C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe it won't open my profile, just a non signed-in version of chrome :(
If I use
C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe
instead it returns this error:
Traceback (most recent call last):
File "C:\Users\oacoo\OneDrive\Desktop\bots\bot\xoldver\likesmodule\password reset\passcode.py", line 18, in <module>
driver = webdriver.Chrome('C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe', options=options)
File "C:\Users\oacoo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\oacoo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "C:\Users\oacoo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 109, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service C:\Users\oacoo\AppData\Local\Google\Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0
help me load a page using my chrome profile please!

How to fix PermissionError: [Errno 13] Permission denied:

so I'm trying to launch a selenium instance that comes installed with metamask build version 9.8.4 and now I'm trying to get Selenium to click on buttons and complete the sign-in process through importing from recover seed phrase. Everything was going well until I tried to click the "Get Started" button via selectors where I come across the PermissionError. I tried running the code through my text editor & CMD both with Admin permissions however I still get the same errors.
My Source Code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_extension('metamask-extension-9.8.4')
driver = webdriver.Chrome('./chromedriver', options = options)
driver.get('https://google.com')
time.sleep(5)
get_started_button = driver.find_element_by_css_selector('//*[#id="app-content"]/div/div[3]/div/div/div/button')
get_started_button.click()
input('Press [ENTER] to close browsers...')
driver.quit()
Full Error Log:
Python - script.py:6
Traceback (most recent call last):
File "D:\Rias\Mekaverse Spoof\script.py", line 8, in <module>
driver = webdriver.Chrome('./chromedriver', options = chrome_options)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 64, in __init__
desired_capabilities = options.to_capabilities()
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\options.py", line 202, in to_capabilities
chrome_options["extensions"] = self.extensions
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\options.py", line 109, in extensions
file_ = open(ext, 'rb')
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\User\\Desktop\\Rias\\Mekaverse Spoof\\metamask-extension-9.8.4'
[Finished in 0.832s]

Selenium error in python 3 || lib\subprocess.py [duplicate]

when i run my script , i got this error
Traceback (most recent call last):
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 992, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/ishaq/AppData/Local/Programs/Python/Python36/headless.py", line 9, in <module>
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), chrome_options=chrome_options)
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Users\ishaq\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
here is my script
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.binary_location =
r'C:\Users\ishaq\Desktop\chrome\chromedriver.exe'
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"),
chrome_options=chrome_options)
driver.get("http://www.duo.com")
magnifying_glass = driver.find_element_by_id("js-open-icon")
if magnifying_glass.is_displayed():
magnifying_glass.click()
else:
menu_button = driver.find_element_by_css_selector(".menu-trigger.local")
menu_button.click()
search_field = driver.find_element_by_id("site-search")
search_field.clear()
search_field.send_keys("Olabode")
search_field.send_keys(Keys.RETURN)
assert "Looking Back at Android Security in 2016" in driver.page_source
driver.close()
If we analyze the logs it seems the main issue is with in start os.path.basename(self.path) and subsequent error message:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
So it's clear from the error that the Python client was unable to locate the chromedriver executable binary.
You need to take care of a couple of things as follows:
chrome_options.binary_location : The parameter points to the chrome.exe not the chromedriver.exe
os.path.abspath("chromedriver") will pick up the file path of chromedriver but won't append chromedriver.exe at the end.
Here is the sample code on my windows-8 system to start google-chrome-headless:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("http://www.duo.com")
print("Chrome Browser Initialized in Headless Mode")
driver.quit()
print("Driver Exited")

Login on Instagram using python but it gives error

I have made a code where I try to login to my instagram account but it gives me many errors. How can I fix them?
The code:
import pdb
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get('https://www.instagram.com/accounts/login/')
dom = driver.find_element_by_xpath('//*')
pdb.set_trace()
username = dom.find_element_by_name('username')
password = dom.find_element_by_name('password')
login_button = dom.find_element_by_xpath('//*[#class="_qv64e _gexxb _4tgw8 _njrw0"]')
username.clear()
password.clear()
username.send_keys('your username')
password.send_keys('your password')
login_button.click()
driver.get('https://www.instagram.com/accounts/login')
if 'logged-in' in driver.page_source:
print 'Logged in'
The error:
Warning (from warnings module):
File "C:\Users\Usuario\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 49
warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless '
UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead
Traceback (most recent call last):
File "C:\Users\Usuario\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\Usuario\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 775, in init
restore_signals, start_new_session)
File "C:\Users\Usuario\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] El sistema no puede encontrar el archivo especificado
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Usuario\Desktop\Programaciones Python\Pruebas.py", line 4, in
driver = webdriver.PhantomJS()
File "C:\Users\Usuario\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 56, in init
self.service.start()
File "C:\Users\Usuario\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH.
The error message is telling you exactly what's wrong here: Message: 'phantomjs' executable needs to be in PATH.
You can fix this by locating your phantomjs.exe file -- wherever you downloaded phantomjs driver -- and adding it to your Path environment variable. This guide will help get you started in fixing this. The issue does not need to be fixed in your code, unless you want to manually pass the path to phantomjs.exe into your driver = webdriver.PhantomJS() call.

Categories