Search code examples
c#htmlseleniumbddspecflow

Input full html in textArea using Selenium


I have a textarea and I need to input a full HTML there.

At the BDD I´ll pass the path of the file, but I don´t know how to capture the full HTML (with tags) to apply in the Textarea by SendKeys.

I´m using 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" |   

Inside the method:

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

I want to open the file, read all the html, save it in some var / string and then, pass it to the textArea.


Solution

  • Just read the contents and then pass it to the text area, in your step def.

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