Selenium(with python):如何在wiki textarea中输入任何文本

时间:2018-07-03 06:13:59

标签: python selenium selenium-webdriver textarea

我对Selenium有一个问题,该如何将文本输入到textarea(wiki textarea)中?以下是我的原始HTML,请帮助我解决这个问题。非常感谢你!

<textarea class="textarea long-field wiki-textfield mentionable wiki-editor-initialised wiki-edit-wrapped" cols="60" id="comment" name="comment" wrap="virtual" data-projectkey="PE15" data-issuekey="PE15-2181" resolved="" style="min-height: 174px; max-height: 369px;"></textarea>

2 个答案:

答案 0 :(得分:0)

text_area = driver.find_element_by_id('comment')
text_area.send_keys("This text is send using Python code.")

答案 1 :(得分:0)

根据您提供的将字符序列发送到文本区域的HTML,您需要按以下步骤诱导 WebDriverWait

  • CSS_SELECTOR

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea.textarea.long-field.wiki-textfield.mentionable.wiki-editor-initialised.wiki-edit-wrapped#comment"))).send_keys("Ben_C")
    
  • XPATH

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//textarea[@class='textarea long-field wiki-textfield mentionable wiki-editor-initialised wiki-edit-wrapped' and @id='comment']"))).send_keys("Ben_C")
    

注意:您必须添加以下导入:

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