Selenium not able to load dynamic options in a dropdown - selenium

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);

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.

Related

How to indicate certain events to Selenium tests?

I'm relatively new to Selenium testing. I have a React SPA I want to create Selenium tests for. I can work with locators and such, but I don't know how I can make the test wait for certain events.
I.e.: The test opens a page where I have a list that is loaded via an API. I need the test to wait until the content is loaded. How can I indicate this to the test? I may be able to check the spinner and wait until it disappears, but there could be situations when the spinner doesn't even appear. Besides, I need to handle events when there are no elements in the list or when there is a communication issue with the API. I really don't want to rely on user messages and spinners.
Should I create an DOM element which is invisible to the user and fill it with the event result so the test can read it? This also doesn't seem a good solution for me.

Problem of Jmeter/Webdriver with testing a webapp searching data form which has Knockout installed

I am facing problem of testing jmeter/Webdriver for a webapp which has Knockout framework installed. I fill all the form fields OK but when run click search button it displays the error that required fields need not to be empty. I checked all web element value are not empty. As my understand Knockout is not activated to bind Web elements with DataModel from Knockout. I used wait WDS.browser.manage().timeouts().implicitlyWait for webpage fully loaded/ajax calling or event being fired but without any success. I Do you have any experiencing and solution for testing this kinds of webapp?
thanks
It might be the case you need to trigger a certain JavaScript event in order to "tell" the web application that you finish the input, i.e. onkeyup or onblur which is not being automatically called by Selenium's sendKeys() function
You can use i.e. WDS.browser.executeScript() function to send the event(s) which indicate that you filled in the form(s). Check out The WebDriver Sampler: Your Top 10 Questions Answered article to learn how to call scripts, use Waits, etc.

What is the proper way to test mandatory field in selenium

I am testing my web application using Selenium. All the form validation in the web application is done by HTML5 and some JS(for safari browser). I want to know what is the proper way to test the form validation.
Currently I am using one approach, i.e Before I filled up a mandatory field I clicked on the submit button. If the page is not refreshed then I assume the form validation working correctly. But I think there should be a better approach to do it. I am unable to find any proper solution. Any suggestion will be highly appreciated.
I also go through this link. But it is not working for me because it is not enough to have required attribute (eg required attribute does not work in older Safari browser).
Rather than checking if the page is refreshed or not, you should instead expect that it is not and that a certain error message or field highlighting or something is applied to the current page. When in an error state, the input fields probably get given an extra class, or an error div/span might be added to the DOM, try checking for that sort of thing

Persisting DOM en cache problems using Selenium on SlickGrid

I'm testing (using Selenium) a site containing a slickgrid.
To find the correct field to enter a value, I have to apply a filter, and then double click the field to enter the data.
The problem is, that after applying the filter nine out of ten times Selenium ends up with an exception that the element is no longer attached to the DOM, or is not present in the cache anymore. One out of ten doesn't fail on this point.
I've tried about every bit of advice I can find on this issue, but none has brought any sufficient help. Waiting an looping until the element is present, visible etc. doesn't work.
So: is there a way to have Selenium locate an element in a slickgrid after the page has changed because of a filter action?
Thanks!

Selenium: Loop Through Each <option> in Drop Down List

I'm using Selenium to ease my testing burden and I have about 1,000 different drop down list combinations (spread across multiple pages and drop down lists) that need to be tested. Basically, what I would like to do is select each <option> inside of a <select>, click the Submit button, select an item (first, second, third, etc.) in the drop down list on the resulting page, click submit, and then go back and select the next item, in sequence. Each time, it should assert that a certain value (related to the drop down list value selected) is present on the final page. Does anybody know if this kind of logic is possible in Selenium?
I'm having a hard time explaining this, so hopefully this pseudo code clears things up
foreach option in select
select option
submit form
foreach option in select
select option
submit form
assert that page contains text that matches selected values
Edit: I have selected values from the drop down list while the recorder is playing, but it seems like the recorder isn't picking up the selected drop down list values. Nor have I been able to figure out how to perform the operation for each <option> in a <select>.
The first question I have is whether or not it's even possible. If it is, could somebody please point me in the right direction to get me started?
Edit 2: I'm not opposed to using another web automated testing utility. If anybody has any recommendations for a free alternative, please feel free to make that recommendation.
What language are using Selenium in? If you're just using Selenium by writing HTML, I'd recommend switching to a programming language and using Selenium RC -- bindings are available for a wide variety of languages, such as Java and Python. In Java, I believe the following would do what you want:
void test(Selenium browser, String startPageUrl,
String firstFormLocator, String firstSelectLocator,
String secondFormLocator, String secondSelectLocator) {
browser.open(startPageUrl);
for (String option : browser.getSelectOptions(firstSelectLocator)) {
browser.open(startPageUrl);
browser.select(firstSelectLocator, "label=" + option);
browser.submit(firstFormLocator); // Or click the submit button
for (String subOption : browser.getSelectOptions(secondSelectLocator) {
browser.open(startPageUrl);
browser.select(firstSelectLocator, "label=" + option);
browser.submit(firstFormLocator); // Or click the submit button
browser.select(secondSelectLocator, "label=" + subOption);
browser.submit(secondFormLocator); // Or click the submit button
// Do your assertions
}
}
}
The code isn't exactly readable, so it might be worth some time abstracting the page away slightly using the Page Object pattern. This also helps make the code more maintainable, for instance when you change the ID of an element, you only need to change it in the page object rather than every test.
Also bear in mind that doing this 1000 times isn't going to be quick. It might be worth seeing if you do similar testing just below the web interface to allow quicker feedback from tests, and then test the web interface is using the lower layer correctly. Also, do you really need 1000 tests? It seems that there's some redundancy in testing here -- is the 1000th test going to fail if the last 999 have passed?