如何让 Selenium 在 DeepL.com 内发送文本
How to make Selenium send text within DeepL.com
网站:DeepL
要翻译的原文的 XPath:
//textarea[contains(@class, 'lmt__source_textarea')]
错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//textarea[contains(@class, 'lmt__source_textarea')]"}
我也在传递饼干。
注意:XPath 适用于 Chrome 开发工具。
要在元素内发送 字符序列,您需要归纳 WebDriverWait for the and you can use the following :
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")
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
浏览器快照:
网站:DeepL
要翻译的原文的 XPath:
//textarea[contains(@class, 'lmt__source_textarea')]
错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//textarea[contains(@class, 'lmt__source_textarea')]"}
我也在传递饼干。
注意:XPath 适用于 Chrome 开发工具。
要在元素内发送 字符序列,您需要归纳 WebDriverWait for the
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")
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
浏览器快照: