首页 > 解决方案 > 使用 Selenium 在 textArea 中输入完整的 html

问题描述

我有一个文本区域,我需要在那里输入一个完整的 HTML。

在 BDD 中,我将传递文件的路径,但我不知道如何捕获完整的 HTML(带标签)以通过 SendKeys 应用于 Textarea。

我正在使用 Specflow + Selenium + C#

Scenario Outline: Input Disclaimer Filme
  Given I choose the type of disclaymer <type>
  When I open the html file <file>
  Then I send then 

  Examples:
    | type               | file                                  | 
    |    "Cota Capital"  |   "C:\Disclaimers\CotaCapital.html"   |    
    |    "Caucionamento" |   "C:\Disclaimers\Caucionamento.html" |   

方法内部:

driver.FindElement(By.Id("TxtConteudo")).SendKeys(fullHtml);

我想打开文件,读取所有 html,将其保存在一些 var / string 中,然后将其传递给 textArea。

标签: c#htmlseleniumbddspecflow

解决方案


只需阅读内容,然后在您的步骤 def 中将其传递到文本区域。

string fullHtml = File.ReadAllText(file);
char tab = '\u0009';
fullHtml = fullHtml.Replace(tab.ToString(), "");
driver.FindElement(By.Id("TxtConteudo")).SendKeys(fullHtml);

推荐阅读