Chrome WebDriverException using selenium - python-3.x

Before you rate me, I must say that I read almost every answer on this site about who had my same problem, but i found no answer.
For example there the one who asked the question accepted the first answer, but copy-pasting the code in the answer the same error was raised.
An other example there where is linked this video, which doesn't explain much, but there no error is raised, instead of my code when I copied it from the video. (he doesn't write .exe, so probably an error would be found in his code too)
This one has exactly my same problem, so it would be perfect, but no answer was accepted.
Here's the last line of the error:
selenium.common.exceptions.WebDriverException: Message: 'chrome.exe %s' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
At the end of the exception message there's a link, which says they migrated to another site.
The error message here:
FileNotFoundError: [WinError 2] Impossibile trovare il file specificato
During handling of the above exception, another exception occurred:
#Something else beetwen
selenium.common.exceptions.WebDriverException: Message: 'chrome.exe %s' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Here's the beginning of my code:
from selenium import webdriver
chrome_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
driver = webdriver.Chrome(executable_path=chrome_path)
I'm sure the path is correct, 'cause I copy-pasted it from the chrome.exe properties.
I also tried it without %s, and it raises a different error:
selenium.common.exceptions.WebDriverException: Message: Service C:/Program Files (x86)/Google/Chrome/Application/chrome.exe unexpectedly exited. Status code was: 0
Can someone help explaining me what's wrong?
Thanks
EDIT
I searched with file explorer for "chromedriver", and nothing was found.

You can try as following
driver = webdriver.Chrome(executable_path=r'Path_to_chrome_Driver\\chromedriver.exe')
You are locating chrome browser exe location. Please download chrome driver for selenium Chromedriver. Then enter the chrome driver location.
Note: Make sure you have downloaded the correct chromedriver based on your chrome browser version.

As I see your path is to Chrome (browser) exe file instead of chromedriver.exe used by Selenium

Related

Python Selenium Remote Webdriver Upload File

I am using python 3.9 and selenium 4.6.0 on Chrome. I have a script that needs to upload a file to an input, this works fine on local but fails when run on RemoteDriver. The code I am using is
driver.find_element(By.XPATH, "//input[#accept]").send_keys('path to file')
When run on RemoteDriver the error returned is
selenium.common.exceptions.WebDriverException: Message: unknown command: unknown command: session/cddd71e067d7717481fb8a635103c643/se/file
I've think it is due to this line in the remote_connection.py file in selenium
Command.UPLOAD_FILE: ('POST', "/session/$sessionId/se/file")
From the research I've done the 'se' in this case is a 'vendor_prefix' for selenium but I cannot figure out how to either configure the remote driver to use a vendor prefix or remove that from POST path that is being passed (short of pulling my own version of the code and maintaining that).
For other functional reasons I can't revert to selenium 3x (which is an option I've seen to correct this), nor can I set w3c to False. Does anyone know how to work around this particular issue; either by getting send_keys to operate as expected in this situation or using another method to upload the file? Thanks.

How to use specific Chrome profile with selenium python

Please don't mark this is as duplicate first read my problem properly..
This is my code:
options = webdriver.ChromeOptions()
options.add_argument(r"--user-data-dir=C:\\Users\\Pranil.DESKTOP-TLQKP4G.000\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument(r'--profile-directory=Profile 1')
browser = webdriver.Chrome(ChromeDriverManager().install(), options=options)
browser.get('https://web.whatsapp.com')
And this is the error I get:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
I tried the solutions given here:
InvalidArgumentException: Message: invalid argument: user data directory is already in use error using --user-data-dir to start Chrome using Selenium
The problem is that the Default and Profile 1 are in the same directory User Data(Creating a new profile doesn't solve the problem as mentioned in above answer)..So if I run this script with my another chrome tab with 'Default' profile running in background this error appears..How can I make sure that this error goes away(I can't close the other chrome tabs with Default profile while running this script)

Python Selenium Error: user data directory is already in use [duplicate]

When I am trying to use --user-data-dir for the current user to start Chrome using Selenium I am getting an error as:
File "C:\Program Files (x86)\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Program Files (x86)\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
How can I fix this error?
This error message...
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
...implies that the ChromeDriver was unable to initiate the new Chrome Browser session using the specified user data directory as it was already in use.
This error can be reproduced as follows:
Code Block:
from selenium import webdriver
import getpass
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument(r"--user-data-dir=C:\Users\{}\AppData\Local\Google\Chrome\User Data".format(getpass.getuser()))
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.google.com/")
Complete relevant traceback:
[12148:21412:0204/035557.731:ERROR:cache_util_win.cc(21)] Unable to move the cache: Access is denied. (0x5)
[12148:21412:0204/035557.731:ERROR:cache_util.cc(141)] Unable to move cache folder C:\Users\Soma Bhattacharjee\AppData\Local\Google\Chrome\User Data\ShaderCache\GPUCache to C:\Users\Soma Bhattacharjee\AppData\Local\Google\Chrome\User Data\ShaderCache\old_GPUCache_000
[12148:21412:0204/035557.731:ERROR:disk_cache.cc(178)] Unable to create cache
[12148:21412:0204/035557.731:ERROR:shader_disk_cache.cc(605)] Shader Cache Creation failed: -2
Opening in existing browser session.
Traceback (most recent call last):
File "C:\Users\Soma Bhattacharjee\Desktop\Debanjan\PyPrograms\yandex_ru.py", line 18, in <module>
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
File "C:\Python\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
Analysis
The error stack trace clearly complains of Access is denied as the program was unable to move the cache folder ..\ShaderCache\GPUCache to ..\ShaderCache\old_GPUCache_000. hence the creation of cache failed and subsequently creation of Shader Cache Creation failed. Though these issues raises the InvalidArgumentException but forcefully able to open a new window within the existing Chrome Browser Session.
Though the error is thrown, still the new Chrome window gets initiated but remains attached with the already opened Chrome session but the new window can't be controlled by the WebDriver instance. Hence you see data:, in the url bar.
Solution
You need to take care of a couple of things:
If you are using the Default Chrome Profile to access webpages for your other work on the same Test Machine, you shouldn't set user-data-dir as the User Data as it remains locked by the other Chrome process you have initiated manually.
In the above scenario you need to create and use another Chrome Profile and you can find a detailed discussion in How to open a Chrome Profile through Python
If you are executing your tests in a isolated test system, you can set user-data-dir as ..\User Data\Default to access the Default Chrome Profile.
In the above scenario you need to create and use another Chrome Profile and you can find a detailed discussion in How to use Chrome Profile in Selenium Webdriver Python 3
However as per best practices you must always create a new Chrome Profile to execute your tests as the Default Chrome Profile may contain Extensions, Bookmarks, Browsing History, etc, and may not load properly.
You can find a detailed discussion in How to open a Chrome Profile through --user-data-dir argument of Selenium
The simplest and easiest fix is; to clear existing opened chrome driver: Here're the steps: type task manager to the Spotlight Search/in the Search Window at the task bar or using other ways accessing to task manager. When the Task Manager Wizard/window pops up, search chromedriver, right click on it and then click "End Task". That's it. It's not an eternal fix. Once you opened chrome browser multiple times, you got to do the same step avoid the issue. Hope this helps as am looking for a stable fix.
Just had the same problem trying to skip the login process and the solution was to close the already openned browser.
As Tes answer mentioned, I opened up the Windows Task Manager and I closed all the chrome.exe and chromedriver.exe processes and it worked!!!
I used these configurations to open Google Chrome using my Chrome Profile:
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=C:\\Users\\my_user\\AppData\\Local\\Google\\Chrome\\User Data')
driver = webdriver.Chrome(executable_path='./chromedriver.exe', options=options)
System.setProperty("webdriver.chrome.driver", "C://Users//Mhamed//Desktop//chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(options);
driver.manage().window().fullscreen();
driver.get("");

Cant Acess The Voice Model File

I am trying to write a code for voice assistant but having problem in accessing my voiceModel file after saving.
Can anyone help me out please:)
My Code:
def talk(voiceModel):
print(voiceModel)
for line in voiceModel.splitlines():
text_to_speech=gTTS(text='Welcome To Inspiration',lang='en-uk')
text_to_speech.save('voiceModel.mp3')
mixer.init()
mixer.music.load('voiceModel.mp3')
mixer.music.play()
os.remove("voiceModel.mp3")
And I Got this error:
File "C:/Users/Harsh/Desktop/Projects/Python/Inspiration/Inspire.py", line 23, in talk
os.remove("voiceModel.mp3")
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'voiceModel.mp3'
So I just want help to be within limit of accessing my file always without changing my program code a lot:
Plzz Help???
Btw I went here but its not much of help to me Stack Overflow

Python pickle question. I don't know why this error occurred

Before I ask you, please understand that I am not good at English. im sorry.
import...
sharedMem_chk=mp.Value(ctypes.c_bool,False)
def all_loopStop(chk):
#print("[def]all_loopStop:::ready")
while True:
if chk.value==False:
if keyboard.is_pressed('q'):
print("::stop loop::")
chk.value=True
def __init__():
test1 = mp.Process(target=all_loopStop, args=(sharedMem_chk,))
test1.start()
if __name__ == '__main__':
__init__()
This is part of my code.
It works fine when compiling and debugging, but when I write an exe file with cx_freeze and run the exe file I get the following error message:
_pickle.PicklingError: Can't pickle : attribute lookup all_loopStop on main failed
After searching for an hour, I think the reason for the error is data not serialized, but the all_loopStop function has not needed serialized data, so I don't know why the error occurs.
The development environment is python3.7 32bit, and I'll also attach a detailed debug console window.
I need your help very much. I apologize once again for asking questions with my poor English.
Debug console screenshot

Resources