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.
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
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("");
I am trying to take screenshot of latest email in outlook (OWA) using selenium chromedriver and python code. I am new to selenium so I'm definitely missing how to open element in new window and take screen.
python version: 3.7
headless chrome version: 84.0.4147.89
I am able to login and select latest email. When I try to click() the latest email element it doesnt show any error but when I try to send keys like ENTER to open it in new window, it gives me error saying
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
Need inputs as to how I can open the latest email and save it as image.
Code I've used:
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=1920x1080")
chrome_options.add_argument("start-maximized");
chrome_options.add_argument("disable-infobars")
chrome_options.add_argument("--disable-extensions")
chrome_driver = os.getcwd() + "/chromedriver"
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=chrome_driver)
# login part
driver.get("my OWA url")
username = driver.find_element_by_id("username")
password = driver.find_element_by_id("password")
username.send_keys("my user name")
password.send_keys("password here")
driver.find_element_by_css_selector("input.btn").click()
# To reach to email list and latest email
latest_email = driver.find_elements_by_id("vr")[0]
latest_email.click()
#WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.ID, 'vr')))
#latest_email.send_keys(Keys.ENTER)
print(latest_email.is_selected())
print(latest_email.is_displayed())
time.sleep(5)
driver.save_screenshot("just_to_see.png")
driver.close()
Above code when executed says element is displayed (true), but false for element is selected. It also shows screen where latest email is selected.
When I uncomment the send keys and WebDriverWait, then it gives error saying Selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
I'd tried other options like like move_to_element() and also by clicking on cData class, but unable to get latest email opened.
If it helps someone, it worked when I used below
ActionChains(driver).double_click(latest_email).perform()
Then switched to the new window and iframe which contains the message. Able to get the message..
File "C:/Users/User/Test.py", line 58, in <module>
.send_keys(DTD) \
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
from invalid argument: 'value' must be a single Unicode code point
This is the error I encountered when I send_keys to Date filed on Chrome browser.
The followings are my data and part of code.
Data
Part of code
wb = pandas.read_excel(excel.xlsx)
Journal = wb.values.tolist()
for JV in Journal:
DTD = str(JV[0]) #Date
Actions(driver) \ #Make entry to the filed on google chrome browser
.send_keys(DTD) \
.perform()
This error message...
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
from invalid argument: 'value' must be a single Unicode code point
...implies that there was a compatibility issue while converting a non w3c command to w3c standard command.
As per the discussion in ActionChains perform returns exception 'value' must be a single unicode point this issue was observed with appium Version 1.11.1 when used along with ChromeDriver v2.45 setting the standards mode with:
goog:chromeOptions.w3c:true
Excert from release notes:
Resolved issue 2536: Make standards mode (goog:chromeOptions.w3c:true) the default [Pri-2]
Solution
An immediate solution would be to:
Update ChromeDriver to current ChromeDriver v78.0 level.
Update Chrome to current Chrome Version 78.0 level. (as per ChromeDriver v78.0.3904.105 release notes)
tl; dr
A couple of relevant discussions are as follows:
perform() action chain - Getting exception
ActionsChains key_action.pause causes "exception 'value' must be a single unicode point" in Appium Webview or Chromium