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.

I am automating an application which has auto suggest text box. I am facing an issue that sometimes the auto suggest values are not shown up at all. This happens 50% of the time. Worrying part is this never happens when I try manually.

I am using latest version of Selenium WebDriver in .net C# and executing the tests on Chrome.

Here is how the steps are in the Code

  1. Create WebDriver instance
  2. Find the TextBox
  3. TextBox.Click() on the TextBox
  4. TextBox.SendKeys(): I am entering value character wise which reduces the failure rate
  5. WebDriver.wait(wait for dropdown)
  6. TextBox.SendKeys(Keys.DownArrow)
  7. TextBox.SendKeys(Keys.Enter)
  8. TextBox.SendKeys(Keys.Tab)

Any pointers will really be helpful

share|improve this question
    
I suppose that the suggest text box does not disappear after some time, right? –  l19 Jan 17 at 3:23
add comment

4 Answers

Such Intermittent faults are the hardest ones to debug.
What I would like to suggest is to look around:

  1. Run tests under Fiddler. This tool may help you to find http requests with errors. Also, it would be helpful to find the request which gets the suggestion list and reissue it several times (there is an option in context menu – reissue request.)
  2. When the failure had happened, do not close the browser window, but check if there are any JavaScript errors in the Chrome Dev tools console.
  3. Try to add Thread.Sleep before failing line. If the code will pass – that means you need to improve your current WebDriverWait expression, for instance, wait for some different element visibility

If nothing will help, and the problem is not reproducible manually, I would suggest changing the test automation code to use mouse clicks instead of SendKeys()

share|improve this answer
add comment

A little hacky, but might work: You do the SendKeys(), and then wait with a WebDriverWait. I don't really know the C# syntax, but should be similar:

(new WebDriverWait(yourdriver, 10)).until(visibilityOf(theDropdownWebelement));

This would throw a TimeoutException after 10 seconds of not finding the dropdown. Having wrapped all the process in a method, you can do a try/catch where, if you catch the TimeoutException, you just reload the page and try again.

Might not be the most elegant thing ever (at least, I kind of frown upon refreshing pages) but I think it might work.

share|improve this answer
add comment

I use the following procedure to perform a similar tests:

TestBox.Click();
TextBox.Clear();
TextBox.SendKeys("Test Text");
IWebElement autoCompleteOption = driver.FindElement(By.XPath"//a[contains(text(),'Test Text')]";
WaitForElementPresent(autoCompleteOption);
autoCompleteOption.Click();

The wait step is important to ensure that WebDriver doesn't generate a NoSuchElementException.

share|improve this answer
add comment

I would have small sleeps (say 100ms) between each keystrokes. This far more human like then the speed in which Selenium can enter text.

Quite often the auto suggest mechanism may be triggered by delays between keystrokes, and entering quickly via selenium may not trigger.

share|improve this answer
add comment

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.