1

i am facing a problem with selenium , i am inserting a large size of string (String.length = 124354) in text area using firefox browser.

1. ones i pass string on text area

driver.findElement(By.name("name")).sendKeys("my large String");

result : unresponsive script , browser hang

2. 2nd time split string , concat String by according fibonacci series and add in list

result : unresponsive script , browser hang

3. split string , concat string in buch of 5 or 10 `and pass on list

try {
        int h = 0;
        for (i = 0; i < 200; i++)
        {
            d = "";
            n3 = n1 + n2;
            n1 = n2;
            n2 = n3;
            for (int t = 1; t < 6; t++) {
                m++;
                System.out.println(m);
                d = d.concat(gg[m]);
                h++;
            }
            f.add(d);
        }

    } catch (Exception e) {
    e.printStackTrace();
    }
    for (String h : qaw) {
              System.out.println(h);
            driver.findElement(By.name("name")).sendKeys(h);
        }

result : working but taking time.

4. split string and pass one by one

String qq ="my large String";
 String ab[]=qq.split(" ");
  for (String h : ab) {
            System.out.println(h);
            driver.findElement(By.name("name")).sendKeys(h);
        }

result : working but too much slow,

Ardesco
  • 7,281
  • 26
  • 49
Prade jo
  • 79
  • 1
  • 9
  • have you tried without selenium? i.e. manually entering the long string? – MKay Oct 08 '15 at 10:43
  • And what's your question? How to solve this *problem*? Where it comes from? ... – m02ph3u5 Oct 08 '15 at 10:54
  • Please include in your question a [mcve]. What you have in your question right now is not an MCVE but a description of what the MCVE would contain. – Louis Oct 08 '15 at 11:01

3 Answers3

0

Can you try with following code:

WebElement el = driver.findElement(By.name("name"));
String qq ="my large String";
String ab[]=qq.split(" ");
  for (String h : ab) {
        System.out.println(h);
        el.sendKeys(h);
  }
Sadik Ali
  • 1,129
  • 10
  • 26
0

One thing that might be causing a slowdown is that you are refetching the element each time you .sendKeys(). You should be able to fetch the element before the loop and then just .sendKeys() to it repeatedly.

I would break up the string into smaller chunks. I think that .split(" ") is heading in the right direction but depending on your text, you might be splitting the string into a LOT of little pieces. I would use something more like the code below. It breaks the string into chunks of 5000 characters. You should tweak that up and down and see if it makes the script go faster.

WebElement name = driver.findElement(By.name("name")); // do this so you don't refetch the element off the page each time you .sendKeys()
String qq = "my large String";
String[] tokens = qq.split("(?<=\\G.{5000})"); // experiment with different sized numbers here to find the sweet spot
for (String t : tokens)
{
    // System.out.println(t); // don't do this unless you are debugging because this will slow execution
    name.sendKeys(t); // send to the already fetched element
}

For more info on the .split(), see this answer.

Community
  • 1
  • 1
JeffC
  • 22,180
  • 5
  • 32
  • 55
0

finally i got my solution , and i am sharing with you

WebElement element = driver.findElement(By.name("infringing-urls0"));
        ((JavascriptExecutor) driver).executeScript("arguments[0].value = arguments[1];", element, gd.getInflink());
// gd.getInflink() is the string value , that contain a large string 

thanks for your kind suggestion

Prade jo
  • 79
  • 1
  • 9