MasterNone
MasterNone

Reputation: 568

Webdriver simplest way to enter a longstring with sendKeys?

I want to add about 1000 or 10000 repeating letters/words to a textarea with:

driver.findElement(By.name("message")).sendKeys("asdasdsadasdasdasdasdasdasdasd");

I haven't found a proper example how to achieve this.

Upvotes: 1

Views: 612

Answers (1)

Andy Turner
Andy Turner

Reputation: 140319

Just build a string to pass to sendKeys:

StringBuilder sb = new StringBuilder(1000);
while (sb.length() < 1000) {
  sb.append("sequencetorepeat");
}
webElement.sendKeys(sb.toString());

There are more efficient ways to repeat strings, but this is a simple approach for reasonably short strings.

Upvotes: 1

Related Questions