import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from pynput.keyboard import Key, Controller
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
driver = webdriver.Firefox()
driver.get('https://translate.yandex.com/ocr')
upload_file_path = 'Путь к файлу' Вида 'C:\\Users\\User\\Desktop\\img.png'
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/main/div[1]/div[4]/div/div/div')))
element.click()
keyboard = Controller()
keyboard.type(upload_file_path)
time.sleep(2)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="fileContainer"]/div[1]/div[3]/button[3]')))
time.sleep(2)
element.click()
driver.switch_to.window(driver.window_handles[1])
text = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="translation"]/span')))
print(text.get_attribute('innerText'))
time.sleep(5) # время задержки зависит от величины текста
driver.quit()