1

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.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Anil
  • 193
  • 3
  • 14

1 Answers1

1

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Request is sent using [scrapy-selenium](https://github.com/clemfromspace/scrapy-selenium "scrapy-selenium") package. My request: `SeleniumRequest(url="https://www.deepl.com/translator", wait_time=10, wait_until=EC.element_to_be_clickable((By.CSS_SELECTOR, "button.dl_cookieBanner--buttonClose")))`. I get `selenium.common.exceptions.TimeoutException`. – Anil May 05 '22 at 08:16
  • How is request from _Selenium_ and _scrapy-selenium_ treated differently? – undetected Selenium May 05 '22 at 08:19
  • This is how scrapy-selenium handles [request](https://github.com/clemfromspace/scrapy-selenium/blob/2e557f6f2221f2609b5b6c6cf3b609a28387d918/scrapy_selenium/middlewares.py#L97) & [expected conditions](https://github.com/clemfromspace/scrapy-selenium/blob/2e557f6f2221f2609b5b6c6cf3b609a28387d918/scrapy_selenium/middlewares.py#L113). – Anil May 05 '22 at 13:06
  • I'm using docker python interpreter. Program is working properly in local environment *(even without using `WebDriverWait()`)*. My concern is with docker, it isn't able to locate XPath for original text to translate. Other sites *(e.g [DuckDuckGo](https://duckduckgo.com/ "DuckDuckGo"))* is working perfectly with docker python interpreter. – Anil May 05 '22 at 14:04
  • From your code trials it doesn't looks like either _request_ or _expected_conditions_ was a concern, but the _**xpath**_. Did you test the xpath? – undetected Selenium May 05 '22 at 14:07
  • XPath works in local python interpreter & Chrome Dev tools. – Anil May 05 '22 at 14:08
  • I'm not asking about your _xpath_, but the _**xpath**_ I suggested in my answer when implemented in your code. – undetected Selenium May 05 '22 at 14:10
  • Yes your xpath is working in local python interpreter & Chrome Dev tools.. – Anil May 05 '22 at 14:13
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/244511/discussion-between-anil-and-undetected-selenium). – Anil May 05 '22 at 14:15
  • _xpath is working in local python interpreter_: So as per your question, wasn't that the answer you were looking for? – undetected Selenium May 05 '22 at 14:15
  • Let's discuss the issue in [Selenium](https://chat.stackoverflow.com/rooms/223360/selenium) room. – undetected Selenium May 05 '22 at 14:15