Home > front end >  How to make Selenium send text within DeepL.com
How to make Selenium send text within DeepL.com

Time:05-06

Website: DeepL

XPath for original text to translate:

//textarea[contains(@class, 'lmt__source_textarea')]

Error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//textarea[contains(@class, 'lmt__source_textarea')]"}

I'm also passing cookies.

Note: XPath works in Chrome Dev tools.

CodePudding user response:

To send a character sequence within the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategies:

driver.get("https://www.deepl.com/translator")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.dl_cookieBanner--buttonClose"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//textarea[@aria-labelledby='translation-source-heading']"))).send_keys("Good Boy")

Note: You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Browser Snapshot:

deepl

  • Related