<p>要将<em>字符序列</em>发送到<em>文本区域</em>,必须为<code>element_to_be_clickable()</code>引入<a href="https://stackoverflow.com/questions/49775502/webdriverwait-not-working-as-expected/49775808#49775808">WebDriverWait</a>,并且可以使用以下<a href="https://stackoverflow.com/questions/48369043/official-locator-strategies-for-the-webdriver/48376890#48376890">Locator Strategies</a>之一:</p>
<ul>
<li><p>使用<code>CSS_SELECTOR</code>:</p>
<pre><code>WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea.1[aria-label^='Add a comment'][placeholder^='Add a comment']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea.1.focus-visible[aria-label^='Add a comment'][placeholder^='Add a comment'][data-focus-visible-added]"))).send_keys("Алекс")
</code></pre>
</li>
<li><p>使用<code>XPATH</code>:</p>
<pre><code>WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//textarea[starts-with(@aria-label, 'Add a comment') and starts-with(@placeholder, 'Add a comment')][@class='1']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//textarea[starts-with(@aria-label, 'Add a comment') and starts-with(@placeholder, 'Add a comment')][@class='1 focus-visible' and @data-focus-visible-added]"))).send_keys("Алекс")
</code></pre>
</li>
<li><p><strong>注意</strong>:您必须添加以下导入:</p>
<pre><code>from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
</code></pre>
</li>
</ul>