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]
Related
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")
I am using the following code to search google and click on first search result.
from selenium import webdriver
import urllib.parse
import time
from selenium.webdriver.firefox.options import Options
options = Options()
options.set_preference("dom.popup_maximum", 100)
options.add_argument("-profile")
options.add_argument("/home/blueray/.mozilla/firefox/5ertyoox.default-release")
options.page_load_strategy = 'eager'
# options.add_extension('fhnegjjodccfaliddboelcleikbmapik.crx')
browser = webdriver.Firefox(options=options)
with open("google-search-terms.adoc") as fin:
for line_no, line in enumerate(fin):
line = line.strip()
query = urllib.parse.urlencode({'q': line + " site:amazon.com"})
browser.execute_script(f"window.open('https://www.google.com/search?{query}');")
time.sleep(5)
for x in range(1, len(browser.window_handles)):
browser.switch_to.window(browser.window_handles[x])
try:
elm = browser.find_elements_by_xpath(
'/html/body/div[7]/div/div[9]/div[1]/div/div[2]/div[2]/div/div/div[1]/div/div/div[1]/a/h3')
if not elm:
elm = browser.find_elements_by_xpath(
'/html/body/div[7]/div/div[9]/div[1]/div/div[2]/div[2]/div/div/div[1]/div/div/div/div[1]/a/h3')
elm[0].click()
except Exception as e:
print("Error", str(e))
However, if one instance of firefox is open and I run the script it gives the message:
Firefox is already running, but is not responding. To use Firefox, you
must first close the existing Firefox process, restart your device, or
use a different profile.
And the program is terminated with the following error:
Traceback (most recent call last):
File "google-search-amazon-less-captcha.py", line 13, in <module>
browser = webdriver.Firefox(options=options)
File "/home/blueray/.local/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/home/blueray/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/blueray/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/blueray/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/blueray/.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 0
What should i do so that there is no error even if an instance of firefox is already open?
I'm having the same issue but only if the open firefox instance has the same profile that I'm loading in the script. If you remove the profile from this script it should run. It should also work if your code uses a different profile that the current open window is using.
You can also use the deprecated selenium 3 way of loading a profile and this avoids the error for me.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
ffOptions = Options()
ffProfile = FirefoxProfile(r'C:\Users\Tyler\AppData\Roaming\Mozilla\Firefox\Profiles\0753x1pz.default')
ffOptions.profile = ffProfile
driver = webdriver.Firefox(options=ffOptions)
driver.get("http://www.google.com")
I'm still looking for a viable solution using the selenium 4 way of setting a profile.
Sometime, Selenium scripts are leaving web drivers open, not closing them properly.
A good pratice would be a good try/except/finally block:
driver = webdriver.Firefox()
try:
# Your code
except Exception as e:
# Log or print error
finally:
driver.close()
driver.quit()
Also, you should trying to kill any firefox processes running on your system as part of a python script, using something like this:
.....
.....
import os
os.system("taskkill /im geckodriver.exe /f")
os.system("taskkill /im firefox.exe /f")
I am very new to python and trying to build a solution using Python + Selenium.
I have created a module to initialize my webdriver:
DriverEngine.py:
import os
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from MyFirstSeleniumPyProject.FrameworkEngine.Constants import BrowserConstants
class DriverInitialize:
def InitializeChromeDriver(self):
browser_name = BrowserConstants.Chrome
print(browser_name)
driver = DriverConfiguration.ConfigureChromeDriver(None)
return driver
class DriverConfiguration:
def ConfigureChromeDriver(self):
driver = webdriver.Chrome(ChromeDriverManager().install())
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("window-size=1920,1080")
# preferences
chrome_options.add_experimental_option('prefs', {
'download.default_directory': get_download_path(),
'profile': {
'password_manager_enabled': False,
'disable-popup-blocking': 'true'
}
})
driver = webdriver.Chrome(chrome_options=chrome_options)
return driver
def get_download_path():
dir_path = os.getcwd()
return dir_path
I'm trying to invoke above driver function in my test file:
Chrome_Test.py
from MyFirstSeleniumPyProject.FrameworkEngine.Drivers import DriverEngine
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
class AssertGooglePage:
def navigate_url(self,url):
self.driver = DriverEngine.DriverInitialize.InitializeChromeDriver(None)
self.driver.get(url)
AssertGooglePage.navigate_url(None, url="https://www.google.com")
ErrorLog:
C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\venv\Scripts\python.exe C:/Users/user/PycharmProjects/TestAutomation.Selenium.Practice/MyFirstSeleniumPyProject/Tests/Chrome_Test.py
Chrome
[WDM] - Current google-chrome version is 84.0.4147
[WDM] - Get LATEST driver version for 84.0.4147
[WDM] - Driver [C:\Users\user\.wdm\drivers\chromedriver\win32\84.0.4147.30\chromedriver.exe] found in cache
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\venv\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\sande\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\sande\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
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/user/PycharmProjects/TestAutomation.Selenium.Practice/MyFirstSeleniumPyProject/Tests/Chrome_Test.py", line 10, in <module>
my = AssertGooglePage.navigate_url(None, url="https://www.google.com")
File "C:/Users/user/PycharmProjects/TestAutomation.Selenium.Practice/MyFirstSeleniumPyProject/Tests/Chrome_Test.py", line 7, in navigate_url
self.driver = DriverEngine.DriverInitialize.InitializeChromeDriver(None)
File "C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\MyFirstSeleniumPyProject\FrameworkEngine\Drivers\DriverEngine.py", line 11, in InitializeChromeDriver
driver = DriverConfiguration.ConfigureChromeDriver(None)
File "C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\MyFirstSeleniumPyProject\FrameworkEngine\Drivers\DriverEngine.py", line 47, in ConfigureChromeDriver
driver = webdriver.Chrome(chrome_options=chrome_options)
File "C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\user\PycharmProjects\TestAutomation.Selenium.Practice\venv\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
When I use similar snippet in same file, it works perfectly:
from selenium import webdriver
#import chromedriver_binary
from webdriver_manager.chrome import ChromeDriverManager
import time
# Select webdriver
driver = webdriver.Chrome(ChromeDriverManager().install())
# Select page load time out
driver.set_page_load_timeout(10)
# Navigate to url
driver.get("https://www.google.com")
# Sleep
time.sleep(3)
# Assertion
isTitle = driver.title=="Google"
if(isTitle):
print("Google page opened successfully!")
else:
print("Google page did not opened successfully!")
driver.quit()
Can some one suggest what's wrong with my scripts?
Please Note: I am not keeping Chromedriver at any location instead downloading at run time.
Seems like your script does not know where you Chrome Driver (Selenium) is located.
Try to use the following code to point Selenium to where you downloaded the Chrome Driver:
driver = webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe")
I was trying over the past few hours , without success , to make webdriver.Firefox() run properly. I reinstalled geckodriver and verified it was added to the path , i tried to use FirefoxBinary but it didn't help.
I could not find any solution , and I am not sure how to fix this , I would appreciate your help.
This is the code :
#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import time
browser = webdriver.Firefox()
browser.get("https://testweb.com")
time.sleep(10)
username = browser.find_element_by_id("extpatid")
password = browser.find_element_by_id("extpatpw")
username.send_keys("username")
password.send_keys("password")
login_attempt = browser.find_element_by_xpath("//*[#type='submit']")
login_attempt.submit()
Below are the exceptions received when I tried to execute the script :
Traceback (most recent call last):
File "./braude.py", line 7, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
Python version :
# /usr/bin/python -V
Python 2.7.12+
I'm not sure why you have this line:
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
but it's completely unnecessary and likely related to your ultimate problem - a wrong version of the Firefox webdriver module.
Try Chrome and see how it reacts with that.
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?