Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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: http://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')
    textbox.send_keys(search_phrase)
    findb = self.browser.find_element_by_id('findbutton')
    findb.click()

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)})
share|improve this question
    
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

1 Answer 1

up vote 3 down vote accepted

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;
        try
        {
            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             
            doc.LoadXml(results);
        }
        return doc;
    }
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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