May-27-2023, 02:28 PM
Please I need help.
I need it to run in the background while I'm in full screen playing, for example.
I get the code to call chrome, look for the translator, and click the voice translate button when I press "v".
My problem is:
1. the window closes and should remain open.
2. doesn't run in the background causing me to quit the game.
3. clicks on the button but then clicks again (deactivating it)
I need it to run in the background while I'm in full screen playing, for example.
I get the code to call chrome, look for the translator, and click the voice translate button when I press "v".
My problem is:
1. the window closes and should remain open.
2. doesn't run in the background causing me to quit the game.
3. clicks on the button but then clicks again (deactivating it)
from selenium import webdriver from selenium.webdriver.common.keys import Keys import time from selenium.webdriver.common.by import By import keyboard from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options def ejecutar_codigo(): chrome_options = Options() chrome_options.add_argument("--enable-audio-input") chrome_options.add_experimental_option('prefs', {'profile.default_content_setting_values.media_stream_mic': 1}) service = Service('E:\Phyton\chromedriver.exe') driver = webdriver.Chrome(service=service, options=chrome_options) driver.get('http://www.google.com') search_box = driver.find_element(By.NAME, 'q') search_box.send_keys('traductor espaƱol ingles') search_box.send_keys(Keys.RETURN) translator_link = driver.find_element(By.CSS_SELECTOR, '#tw-mic > span.tw-menu-btn-image.CFq0kc.Hnn8f.z1asCe.JXrXlb > svg') translator_link.click() # Espera durante 10 segundos time.sleep(20) # Cierra el navegador driver.quit() def on_key_press(event): if event.name == 'v': ejecutar_codigo() keyboard.on_press(on_key_press) keyboard.wait('esc')