case description
http://sahitest.com/demo/php/fileUpload.htm
click the first button "file",click it
![[Pasted image 20220815111354.png]]
code example
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://sahitest.com/demo/php/fileUpload.htm')
driver.find_element('id','file').click()
error track
D:\Python39\python.exe D:/pythonProject/deom1.py
Traceback (most recent call last):
File "D:\pythonProject\deom1.py", line 8, in <module>
driver.find_element('id','file').click()
File "D:\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 88, in click
self._execute(Command.CLICK_ELEMENT)
File "D:\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 396, in _execute
return self._parent.execute(command, params)
File "D:\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute
self.error_handler.check_response(response)
File "D:\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
(Session info: chrome=104.0.5112.81)
Stacktrace:
Backtrace:
Ordinal0 [0x004F5FD3+2187219]
Ordinal0 [0x0048E6D1+1763025]
Ordinal0 [0x003A3D40+802112]
Ordinal0 [0x003C9171+954737]
Ordinal0 [0x003ECB8C+1100684]
Ordinal0 [0x003C8394+951188]
Ordinal0 [0x003ECDA4+1101220]
Ordinal0 [0x003FCFC2+1167298]
Ordinal0 [0x003EC9A6+1100198]
Ordinal0 [0x003C6F80+946048]
Ordinal0 [0x003C7E76+949878]
GetHandleVerifier [0x007990C2+2721218]
GetHandleVerifier [0x0078AAF0+2662384]
GetHandleVerifier [0x0058137A+526458]
GetHandleVerifier [0x00580416+522518]
Ordinal0 [0x00494EAB+1789611]
Ordinal0 [0x004997A8+1808296]
Ordinal0 [0x00499895+1808533]
Ordinal0 [0x004A26C1+1844929]
BaseThreadInitThunk [0x7635FA29+25]
RtlGetAppContainerNamedObjectPath [0x773A7A9E+286]
RtlGetAppContainerNamedObjectPath [0x773A7A6E+238]
fix code
from selenium import webdriver
from selenium.webdriver import ActionChains
driver = webdriver.Chrome()
driver.get('http://sahitest.com/demo/php/fileUpload.htm')
ele_fie = driver.find_element('id','file')
ActionChains(driver).click(ele_fie).perform()
why
i don't know how to explain this issue. who can tell me, thanks a lot.
In the DOM I see, the input element has attribute type=file, which means it is a file upload dialog that is related to OS and Selenium cannot perform operations on this one directly. Hence ActionChains.
Related
I’m using the default “Remote desktop connection” of Windows to access an Azure virtual machine where I'm using Chrome Webdriver to upload a video on YouTube. The script works fine as long as the RDP is connected and video is uploaded but when I close the “Remote desktop connection” I get the following error:
Traceback (most recent call last):
File "C:\Users\admin23\Desktop\pip\SB\uploader.py", line 45, in <module>
time.sleep(3)
^^^^^^^^^^^^^^
File "C:\Users\admin23\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 93, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\admin23\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 410, in _execute
return self._parent.execute(command, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\admin23\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "C:\Users\admin23\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=107.0.5304.122)
Stacktrace:
Backtrace:
Ordinal0 [0x0057ACD3+2075859]
Ordinal0 [0x0050EE61+1633889]
Ordinal0 [0x0040B680+571008]
Ordinal0 [0x0043BBD6+768982]
Ordinal0 [0x00431C76+728182]
Ordinal0 [0x0045731C+881436]
Ordinal0 [0x004315BF+726463]
Ordinal0 [0x00457534+881972]
Ordinal0 [0x0046B56A+963946]
Ordinal0 [0x00457136+880950]
Ordinal0 [0x0042FEFD+720637]
Ordinal0 [0x00430F3F+724799]
GetHandleVerifier [0x0082EED2+2769538]
GetHandleVerifier [0x00820D95+2711877]
GetHandleVerifier [0x0060A03A+521194]
GetHandleVerifier [0x00608DA0+516432]
Ordinal0 [0x0051682C+1665068]
Ordinal0 [0x0051B128+1683752]
Ordinal0 [0x0051B215+1683989]
Ordinal0 [0x00526484+1729668]
BaseThreadInitThunk [0x7695FEF9+25]
RtlGetAppContainerNamedObjectPath [0x77937BBE+286]
RtlGetAppContainerNamedObjectPath [0x77937B8E+238]
My Code (which works fine when RDP is Open):
import keyboard
from keyboard import press
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.page_load_strategy = "normal"
options.add_argument(r"--user-data-dir=C:\\Users\\admin23\\AppData\\Local\\Google\\Chrome\\User Data\\" )
driver = webdriver.Chrome(options = options)
driver.get("https://studio.youtube.com")
time.sleep(4)
driver.find_element("xpath",'//*[#id="upload-icon"]/tp-yt-iron-icon').click()
time.sleep(3)
elem = driver.find_element("xpath", '//*[#id="select-files-button"]').click()
time.sleep(3)
keyboard.write("file_I_want_to_upload")
press('enter')
time.sleep(3)
driver.find_element("xpath",'//*[#id="next-button"]/div').click()
time.sleep(3)
driver.find_element("xpath", '// *[ # id = "text-container"] / div').click()
time.sleep(3)
driver.find_element("xpath", '// *[ # id = "radio-on"]').click()
time.sleep(3)
driver.find_element("xpath", '//*[#id="save-button"]/div').click()
time.sleep(3)
driver.find_element("xpath",'//*[#id="next-button"]/div').click()
time.sleep(3)
driver.find_element("xpath", '// *[ # id = "checkbox-container"]').click()
time.sleep(3)
driver.find_element("xpath", '//*[#id="submit-questionnaire-button"]/div').click()
time.sleep(3)
driver.find_element("xpath",'//*[#id="next-button"]/div').click()
time.sleep(3)
driver.find_element("xpath", '//*[#id="next-button"]/div').click()
time.sleep(3)
driver.find_element("xpath", '//*[#id="next-button"]/div').click()
time.sleep(3)
driver.find_element("xpath", '//*[#id="privacy-radios"]/tp-yt-paper-radio-button[3]').click()
time.sleep(3)
driver.find_element("xpath",'//*[#id="done-button"]').click()
time.sleep(3)
driver.find_element("xpath", '// *[ # id = "secondary-action-button"] / div').click()
#time.sleep(100)
driver.quit()
I'm in the process of updating Selenium and chromedriver for automated testing purposes. I updated chromedriver and Chrome to version 98, and I went from Selenium v.3.3.3 to 4.1.0.
But I'm getting an unknown error whenever I try and run my test scripts now. The entire traceback is below:
C:\sw\src\Presentation\client\TestAutomationScripts\TestAutomationScripts\TestPlans>python TestPlan_ATO.py
Traceback (most recent call last):
File "TestPlan_ATO.py", line 9, in <module>
class TestPlan_ATO():
File "TestPlan_ATO.py", line 11, in TestPlan_ATO
testPlan = Test(name="TestPlan_ATO")
File "C:\sw\src\Presentation\client\TestAutomationScripts\TestAutomationScripts\TestPlans\TestCases\Test.py", line 113, in __init__
self.driver = WebDriverInstance().driver
File "..\Util\WebDriverInstance.py", line 43, in __call__
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
File "..\Util\WebDriverInstance.py", line 97, in __init__
driver = driverModule(executable_path=driverPath)
File "..\Util\WebDriverInstance.py", line 73, in createChromeDriver
driver = webdriver.Chrome(desired_capabilities=capabilities)
File "C:\Anaconda\lib\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
service_log_path, service, keep_alive)
File "C:\Anaconda\lib\selenium\webdriver\chromium\webdriver.py", line 99, in __init__
options=options)
File "C:\Anaconda\lib\selenium\webdriver\remote\webdriver.py", line 269, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Anaconda\lib\selenium\webdriver\remote\webdriver.py", line 360, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Anaconda\lib\selenium\webdriver\remote\webdriver.py", line 425, in execute
self.error_handler.check_response(response)
File "C:\Anaconda\lib\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process.
Stacktrace:
Backtrace:
Ordinal0 [0x00317AC3+2587331]
Ordinal0 [0x002AADD1+2141649]
Ordinal0 [0x001A3BB8+1063864]
Ordinal0 [0x001BF684+1177220]
Ordinal0 [0x001BCC51+1166417]
Ordinal0 [0x001ED12F+1364271]
Ordinal0 [0x001ECD5A+1363290]
Ordinal0 [0x001E84A6+1344678]
Ordinal0 [0x001C53F6+1201142]
Ordinal0 [0x001C62E6+1204966]
GetHandleVerifier [0x004BDF22+1680738]
GetHandleVerifier [0x00570DBC+2413564]
GetHandleVerifier [0x003AD151+563089]
GetHandleVerifier [0x003ABF13+558419]
Ordinal0 [0x002B081E+2164766]
Ordinal0 [0x002B5508+2184456]
Ordinal0 [0x002B5650+2184784]
Ordinal0 [0x002BF5BC+2225596]
BaseThreadInitThunk [0x75A4FA29+25]
RtlGetAppContainerNamedObjectPath [0x77107A9E+286]
RtlGetAppContainerNamedObjectPath [0x77107A6E+238]
(No symbol) [0x00000000]
I have Chrome on my PATH, but that doesn't seem to make a difference. Under the 'Compatibility' tab in Chrome properties, I've checked 'Run this program as administrator' but, again, that didn't work. I'm not sure what else to do.
Edit 1:
The Anaconda distribution sits on my C drive. The selenium directory is inside the Anaconda directory. When I updated selenium, I got ModuleNotFoundError: 'certifi' in the traceback:
Traceback (most recent call last):
File "TestPlan_ATO.py", line 2, in <module>
from TestCases.Test import Test
File "C:\sw\src\Presentation\client\TestAutomationScripts\TestAutomationScripts\TestPlans\TestCases\Test.py", line 72, in <module>
from Util.WebDriverEventListener import WebDriverEventListener as Listener
File "..\Util\WebDriverEventListener.py", line 25, in <module>
from selenium.webdriver.support.events import AbstractEventListener
File "C:\Anaconda\lib\selenium\webdriver\__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "C:\Anaconda\lib\selenium\webdriver\firefox\webdriver.py", line 24, in <module>
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
File "C:\Anaconda\lib\selenium\webdriver\remote\webdriver.py", line 39, in <module>
from .remote_connection import RemoteConnection
File "C:\Anaconda\lib\selenium\webdriver\remote\remote_connection.py", line 26, in <module>
import certifi
ModuleNotFoundError: No module named 'certifi'
So to fix this error, I went into remote_connection.py and added the first two lines below to the file.
import sys
sys.path.append('/Anaconda/Lib/site-packages/pip/_vendor')
import logging
import socket
import string
import os
import certifi
import urllib3
import platform
I then got another error complaining about testcase.ini, which is the config file that contains the IPs of the systems under test, the login information for the app, etc.
Cannot load C:\Anaconda\Lib\site-packages\pip\_vendor\TestPlans\TestCases\testcase.ini
Traceback (most recent call last):
File "TestPlan_ATO.py", line 5, in <module>
from TestCases.ATO.TestCase_ATO import TestCase_ATO
File "C:\sw\src\Presentation\client\TestAutomationScripts\TestAutomationScripts\TestPlans\TestCases\ATO\TestCase_ATO.py", line 22, in <module>
from Util.UiOps import UiOps as ops
File "..\Util\UiOps.py", line 37, in <module>
class UiOps:
File "..\Util\UiOps.py", line 40, in UiOps
config.load('','testcase.ini')
File "..\Util\ConfigManager.py", line 114, in load
new_dict: dict = self.loader.loadFile(package=package, module=module, filename=filename)
File "..\Util\ConfigLoader.py", line 96, in loadFile
raise IOError('Cannot load ' + config_file)
OSError: Cannot load C:\Anaconda\Lib\site-packages\pip\_vendor\TestPlans\TestCases\testcase.ini
testcase.ini is read every time an automated test is run. The ConfigLoader class returns a config object given a module name and file path relative to ConfigLoader. So I go into ConfigLoader.py and I change the -1s in the try/except block below to -2s:
try:
if self.package:
#If a package is given, use the last entry in sys.path which goes up a directory, and drill down into the package
path = sys.path[-2] + "//" + self.package
else:
#If not, use the information stored in sys.path, and assume we want to look in TestPlans/TestCases
path = sys.path[-2] + "//TestPlans//TestCases"
And that is how I arrived at the Unknown Error which I first posted about.
testcase.ini is also where the browser is selected and the driver path is stored. It looks like this:
; parameters for test framework
[TEST]
DRIVER_PATH = C:\Anaconda\
BROWSER = CHROME
; BROWSER = EDGE
; BROWSER = FIREFOX
CHROME_PATH = C:\Program Files\Google\Chrome\Application\chrome.exe
; EDGE_PATH = C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
; FIREFOX_PATH = C:\Program Files\Mozilla Firefox\firefox.exe
There were two copies of chrome.exe, one in Program Files and another in Program Files (x86). I don't know why there are two separate Google directories in two different C drive subdirectories.
Anyway, I deleted the Google directory in Program Files and kept the one in (x86), and now my test scripts run again.
Related to the solution Trevor discovered, this error may also be caused by the presence of new_chrome.exe within the application's own directory.
The issue affects some other chromium browsers or versions (Brave [106.0.5249.103]; where I had encountered a similar error – CoCreate ProcessLauncherClass failed), but seemingly not all (Microsoft Edge [106.0.1370.42]; could not replicate the issue).
Either way, removal of the substitute executable resolves the error without further issue.
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.binary_location = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
driver_path = r'C:\Program Files\Google\Chrome\Application\chromedriver.exe'
serv = Service(executable_path=driver_path)
driver = webdriver.Chrome(service=serv, options=opts)
driver.implicitly_wait(5)
driver.get('https://www.google.com')
time.sleep(3)
driver.close()
Error:
Traceback (most recent call last):
File "E:/SpiderCode/selenuim_webdirver/demo.py", line 15, in <module>
driver.implicitly_wait(5)
File "E:\pythonProject\test_frame\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1142, in implicitly_wait
self.execute(Command.SET_TIMEOUTS, {
File "E:\pythonProject\test_frame\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
self.error_handler.check_response(response)
File "E:\pythonProject\test_frame\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: 'ms' must be a double
(Session info: chrome=95.0.4638.69)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 6.1.7601 SP1 x86_64)
As you are using chrome=95.0.4638.69 you need to download and use the matching ChromeDriver of chromedriver=95.0.4638.69
This question already has answers here:
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process with ChromeDriver Chrome with Selenium Python
(3 answers)
Closed 2 years ago.
File "C:\Users\u\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\u\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\u\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\u\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\u\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process.
Set chrome driver capabilities and path before launching the driver.
More details here : https://chromedriver.chromium.org/capabilities
Try this approach. No need to maintain chromedriver in your project folder. Just 2 lines of code. Refer here webdriver-manager
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = False
cap = DesiredCapabilities().FIREFOX``
fp = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_profile=fp, options=options,capabilities=cap)
I am attempting to automate a web browser using the environment below:
Windows10, Selenium (v3.141.0), Python (v3.7.4) chrome (v77.0.3865.90), and chromedriver (v77.0.3865.40). I installed pip, installed Selenium(using Python), set my paths in the environmental variables, called out the path to my chromedriver, and I still am running into issues.
-path using for chromedriver: "C:\webdrivers\chromedriver.exe"
-path to Python: "C:\Users\linds\AppData\Local\Programs\Python\Python37"
I have some code that I ran below with errors. Any ideas?
>>> from selenium import webdriver
>>> from selenium.webdriver.chrome.options import Options
>>> options = Options()
>>> options.add_argument('--headless')
>>> options.add_argument('--no-sandbox')
>>> options.add_argument('--disable-gpu')
>>> driver = webdriver.Chrome(options=options, executable_path='C:\webdrivers\chromedriver.exe')
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
driver = webdriver.Chrome(options=options, executable_path='C:\webdrivers\chromedriver.exe')
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.