elements.send_keys() works fine in most cases, but I have a particular test case where I need to input very large strings into a textbox, and send_keys() is far too slow. (The test takes 28 minutes to execute right now!)

There is this way of doing it: https://stackoverflow.com/questions/3526361/firefoxdriver-how-to-disable-javascript-css-and-make-sendkeys-type-instantly

But I want to avoid JavaScript execution if I can. Is there a way to do fast textbox input that's more "native" to WebDriver?

Original code:

    textbox = self.browser.find_element_by_id('query')
    findb = self.browser.find_element_by_id('findbutton')

Solution example code:

with requests.session() as session:
    resp = session.post(PRODUCT_URL + "/login", data={'user_id': USERID,
                                             'password': PASSWORD}).read()
    resp2 = session.post(PRODUCT_URL + "/project/" + PROJECTID +
                   "/search/save", data={'query': QUERY,
                                         'title': str(val)})
  • You did not give a code example. Are you calling send_keys for each character, or once for the entire string? – user246 Dec 28 '11 at 3:30
  • 28 minutes :-O, this is the same time one of my suite takes , having many methods – Tarun Dec 28 '11 at 5:26
  • I'm inputing a large string into a textarea. I'll edit my question above with a code sample. – Aaron Dec 28 '11 at 18:53

To me this appears to be slightly at odds with the purpose of Selenium(Webdriver) which is to imitate user interactions. It may be that you need to take a step back and analyse what the test is looking to achieve (I cannot be sure but it looks like you may not need the UI interaction for this test as it does not seem to be user focused; unless you want to imitate copy and paste of large strings by users?

Have you looked at running this test without selenium? Perhaps by popuating the URI with the strings from a DB or CSV, making the http request within your language of choice and validating the response. In my experience this will make it much faster to complete.

This C# example returns the results of a web request in XML format that can then be parsed and have assertions made against it.

 public XmlDocument NavigateToURI()
        //Text string to populate in URI. 
        //This could also populate from a CSV of DB and run as a for each loop
        string parameter = **********
        string URI = //Build up the URI here including the parameter you want to test
        HttpWebRequest request;
            request = (HttpWebRequest)WebRequest.Create(path);
        catch (Exception ex)
        { throw ex; }

        string results = string.Empty;
        XmlDocument doc;

        // Capture the response
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            Stream stream = response.GetResponseStream();

            StreamReader reader = new StreamReader(stream, Encoding.UTF8);
            results = reader.ReadToEnd();

            doc = new XmlDocument();

            // Read the response into an XML Document             
        return doc;
  • That makes sense. I am going to do it that way. Our product supports searching via the URL. I will put example code in my question above. These comment boxes can't do multi-line code samples. – Aaron Dec 28 '11 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.