0

I have written a selenium data driven code, which will fetch data from the excel file and will ,fill up in the web page. the Webpage contains

  1. drop downs for Country ,State and City,
  2. Text Field 1 and Text Field 2
  3. Add/update Button and Clear Button

Steps

1-select country,state,city ,enter text field 1 and Add/Update button.

Issue

When I perform above action, when Add/update is clicked ,I want page to wait until again starting the loop ,so that the country drop downs resets again. as of now it is not waiting and causing even a new country is selected the state drop-down shows previously selected country's provinces.Example(If I select India and provinces for the 1st record, than next time for United states the "State-drop down" displays ,Indian States but not the United States"

I tried using wait until technique even the driver.manage().timeouts().implicitlyWait(20, TimeUnit.MILLISECONDS), even thread.currentthread.sleep but none of them are consistent as after some records I am getting error as element not found because of the above mentioned issue.

I want post Add/update button is clicked the driver to wait till it again resets the page with default value of the country set Secondly when I pass a value for the country the driver again to wait so that it can load it corresponding States .

toniedzwiedz
  • 17,895
  • 9
  • 86
  • 131
Vikki Lohana
  • 39
  • 2
  • 10
  • couple of questions... after clicking Add/Update button...is ur Page refreshing or it's an Ajax call??? can u please update ur selenium code & HTML as well...used for selecting country dropdown – Anuragh27crony May 26 '14 at 02:29
  • Yes , the page is using the ajax call, i.e. when the add/update button is clicked ,it sets the page with default values ,like for country default value is Unites States, and other text fields as the null. – Vikki Lohana May 26 '14 at 07:31
  • Yes , the page is using the ajax call, i.e. when the add/update button is clicked ,it sets the page with default values ,like for country default value is Unites States, and other text fields as the null. Also ,the code which I have written is not consistent ,means if I execute the code on VPN network the code fails after 14 records. – Vikki Lohana May 26 '14 at 07:40

2 Answers2

1

I hope this could be handled in this way:

Step 1: Write small method where in you send a Webelement and the desired value that you need to select.

Step 2: In that method, before selecting a value from drop down, read the value from it and check for the desired value you looking for.

Step 3: If you don't find the desired value then wait for say 'x' seconds and then loop it again for desired value that you are looking for.

Step 4: Once you get desired value, select it and exit the loop.

By this above method, you can handle as many combo boxes as you like.

For reference: how to read values from combo box

Community
  • 1
  • 1
0

In my opinion you should use some intelligent wait condition here so that it waits until the element gets activated or enabled.

  • Select any value from first drop down
  • Wait until page to be loaded completely
  • Wait until second drop down gets activated
  • Select any value from second drop down
  • Wait until page to be loaded completely
  • Wait until second drop down gets activated

If above solution doesn't work then go for 'refresh', code should be able to refresh the page before selecting any value from first drop down.

     // Code to wait until page get completely loaded
     public void waitUntilPageIsLoaded() {
     ExpectedCondition<Boolean> condition = new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {
            return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
            }
        };
    WebDriverWait wait = new WebDriverWait(driver, timeout);
    wait.until(condition);
    }
Priyanshu
  • 3,040
  • 3
  • 27
  • 34
  • Yes ,I have written the Wait class ,to have custom waits,but still its not working, but will try you above suggestion Also how can I ask Selenium to wait until the page loads.?? – Vikki Lohana May 26 '14 at 07:48
  • Added in above answer, hope it make your code workable. – Priyanshu May 26 '14 at 08:45