Peak Dermutag
Peak Dermutag

Reputation: 103

Selenium WebDriver's SendKeys too slow to fill in <textarea> input

I'm having an issue that SendKeys is too slow. I need to add around 1300 lines to textarea

<textarea id="ctl00_phMainContent_KeywordForm_ControlPanel_txtKeywords" onload="CountLines(this);" onkeypress="CountLines(this);" wrap="off" cols="100" rows="6" name="ctl00$phMainContent$KeywordForm$ControlPanel$txtKeywords"></textarea>

The thing is my login to the website expires and I have to re-login and do that again infinite loop...

Can anyone help me how to appeand the text (lines) Instantly? maybe some Javascript? or Ctrl+c + Ctrl+v? Anyone have a working code?

Upvotes: 3

Views: 4519

Answers (1)

Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83348

You can run JavaScript code in the context of browser opened by a WebDriver.

Use JavaScript evalution to modify HTML DOM tree directly and set <textarea> value.

Evaluating JavaScript in Selenium (Python):

Getting the return value of Javascript code in Selenium

Setting <textarea> value in JavaScript:

 document.getElementById("ctl00_phMainContent_KeywordForm_ControlPanel_txtKeywords").value = "Foobar"

Upvotes: 3

Related Questions