Skyaz123 / imagesnw

0 stars 0 forks source link

selenium #2

Open Skyaz123 opened 1 year ago

Skyaz123 commented 1 year ago

raceback (most recent call last): File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connection.py", line 174, in _new_conn conn = connection.create_connection( File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\util\connection.py", line 72, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "C:\dev\devtools\apps\python3\python-3.9.0\lib\socket.py", line 953, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen httplib_response = self._make_request( File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request self._validate_conn(conn) File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn conn.connect() File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connection.py", line 358, in connect self.sock = conn = self._new_conn() File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connection.py", line 186, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000023F38A7D7C0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\requests\adapters.py", line 489, in send resp = conn.urlopen( File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\connectionpool.py", line 785, in urlopen retries = retries.increment( File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\urllib3\util\retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='chromedriver.storage.googleapis.com', port=443): Max retries exceeded with url: /LATEST_RELEASE_114.0.5735 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000023F38A7D7C0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\requests\api.py", line 59, in request return session.request(method=method, url=url, kwargs) File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\requests\sessions.py", line 587, in request resp = self.send(prep, send_kwargs) File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\requests\sessions.py", line 701, in send r = adapter.send(request, **kwargs) File "C:\dev\devtools\apps\python3\python-3.9.0\lib\site-packages\requests\adapters.py", line 565, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='chromedriver.storage.googleapis.com', port=443): Max retries exceeded with url: /LATEST_RELEASE_114.0.5735 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000023F38A7D7C0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

Process finished with exit code 1

Skyaz123 commented 1 year ago
from selenium import webdriver
from selenium.webdriver.chrome.service import  Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
#options.add_experimental_option("detact", True)

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get("https://www.google.com/")
Skyaz123 commented 1 year ago

Switch the focus to the file upload dialog

wait = WebDriverWait(driver, 10) # Set an appropriate timeout value file_input = wait.until(EC.presence_of_element_located((By.TAG_NAME, 'input[type="file"]')))

Use the send_keys() method to specify the file path you want to upload

file_input.send_keys('C:/path/to/your/file.jpg') # Replace with the actual file path

Optionally, wait for the file upload to complete before continuing

wait.until(EC.invisibility_of_element_located((By.TAG_NAME, 'input[type="file"]')))

Close the browser session

driver.quit()