1

Options for a dropdown on a webpage I am testing are dependent upon the values supplied for earlier textboxes and selects (E.g. based on the currency and amount specified, dropdown for product will show appropriate values. With no values, the supplied the dropdown is blank.).

Now, although I have provided the values for currency and amount, the product dropdown is still blank. It is not fetching the filtered values based on earlier data supplied. I am using Selenium server (2.24.1) and writing scripts in Java in Eclipse with TestNG and testing on IE8.

When inspected, the dropdown is no different from others, only its options change based on the values of other elements on the page. The web application is developed in Java (Wicket framework).

The Selenium code:

selenium.select(ownerBranch, "label=4521 - Branch one");

selenium.select(currency, "label=SEK - Swedish kronor");
Thread.sleep(sleep);

selenium.type(amountSantioned,"100000");
Thread.sleep(sleep);

selenium.click(chooseLoanTermBymatDate);
Thread.sleep(sleep);

timeNow=Calendar.getInstance();
timeNow.add(Calendar.DATE,+360);selenium.type(maturityDate,dateformat.format(timeNow.getTime()));
Thread.sleep(sleep);

selenium.type(amountSantioned,"100000");
Thread.sleep(sleep);

selenium.select(serviceDelChannel, "label=BackOffice");
Thread.sleep(sleep);
selenium.select(product, "label=");
Thread.sleep(sleep*2);
selenium.select(product,"label=LN7292 - Consumer loan for Year2026");
Thread.sleep(sleep);
Virendra Joshi
  • 469
  • 4
  • 8
  • 25
  • How does the page work, internally? What technology does create tha values? What does any inspection tool say to you about the element's HTML? Is it blank, are the elements in there? Could you please show us the relevant piece of your Java code as well as the HTML code of the element? Also! Did you try any other browser? – Petr Janeček Jul 05 '12 at 10:15
  • 1
    Ok I will try with your improvements and revert u back the status Thanks – Virendra Joshi Jul 05 '12 at 10:24
  • I am tried with IE8. But it is still not working.When inspected the dropdown is no different than others only its options changes based upon the values for other elements on the page.My application is developed in Java (Wicket framework). I am pasting java code of my testscript down here : It is pasted in two parts .please look over it – Virendra Joshi Jul 05 '12 at 10:33
  • selenium.select(ownerBranch, "label=4521 - Branch one"); selenium.select(currency, "label=SEK - Swedish kronor"); Thread.sleep(sleep); continued in next cmt selenium.type(amountSantioned,"100000"); Thread.sleep(sleep); selenium.click(chooseLoanTermBymatDate); Thread.sleep(sleep); timeNow=Calendar.getInstance(); timeNow.add(Calendar.DATE,+360); selenium.type(maturityDate,dateformat.format(timeNow.getTime())); Thread.sleep(sleep); selenium.type(amountSantioned,"100000"); Thread.sleep(sleep); selenium.select(serviceDelChannel, "label=BackOffice"); Thread.sleep(sleep); – Virendra Joshi Jul 05 '12 at 10:33
  • selenium.select(product, "label="); Thread.sleep(sleep*2); selenium.select(product,"label=LN7292 - Consumer loan for Year2026"); Thread.sleep(sleep); – Virendra Joshi Jul 05 '12 at 10:34
  • @Slanec please look into it . – Virendra Joshi Jul 05 '12 at 10:36
  • Can selenium.Fireevent command be useful.? – Virendra Joshi Jul 05 '12 at 11:24

1 Answers1

0

I'm not going to try to reproduce the issue (if you can point me to a publicly visible site with similar behaviour, I might test it), so I'm only taking a guess here:

Since Selenium RC is written in pure Javascript and "only" firing change events on selecting values from drop-downs, Wicket is probably waiting for something else or relying on a completely different mechanism.

Things you can try:

  • Use Selenium WebDriver. Selenium RC has been deprecated for over a year now, because it had serious technical limitations (you might have just bumped into one) that are now solved by WebDriver. Also, you won't ever have to use Thread.sleep() again (although I'm almost sure it could be got rid of even here, mostly). This solution is the most painful, but is almost guaranteed to work well, because WebDriver behaves like a real user.
  • Call selenium.fireEvent() on all the input elements you're interacting with. Useful events might be focus, blur, maybe even click in between them.
  • Calling selenium.keyPressNative(String.valueOf(KeyEvent.VK_ENTER)) (presses Enter natively) after you every change of a dropdown. If the changed dropdown is not focused before this, you might need to focus() it beforehand.
  • The painful way that tries to simulate user's behaviour as close as possible instead of using JS methods: Instead of using select(), try to focus() a dropdown element, then select one of its options by pressing Down arrow repeatedly, then Enter.
Petr Janeček
  • 37,768
  • 12
  • 121
  • 145
  • I have been using selenium server for last 6 months, with it not be troublesome to move to webdriver. Actually I have no idea how a webdriver works i use testNG in eclipse. – Virendra Joshi Jul 06 '12 at 12:14
  • To get the difference and for a basic example, see http://stackoverflow.com/questions/4007819/what-is-the-difference-between-seleniums-remote-control-vs-webdriver and http://stackoverflow.com/questions/10285641/selenium-rc-architechture-and-selenium-web-driver-architechture-differences. Also, after you try something to work out the problem, be sure to tell me how it worked :). – Petr Janeček Jul 06 '12 at 17:21
  • Thanks a lot , It worked .First I used fireevent with event "blur" on all my input elements used on the page and then I used the event focus on all my input elements on page.i don't know if I can reduce on the numbner of events called or the number of elements on which I need to use fireevent. But I am carrying on with a default on all elements.Anyway Its a great relief to get rid of it for me and my seniors.Thanks a lot from my team. – Virendra Joshi Jul 09 '12 at 05:47