mardi 20 mars 2018

Jump to initial loop in java

I currently creating a program using Java + Selenium WebDriver, currently having a difficulty of looping technique in Java.

Below is my code:

Assume,

rt = {Capacity Utilization,Overlay Report}

fq = {15 Minute,Hourly,Daily}

Code::

    for( String rt : rep_type ) {
         new Select(driver.findElement(By.name("reporttype"))).selectByVisibleText(rt);
            for( String fq : freq ){

                try {
                Thread.sleep(2000);
                new Select(driver.findElement(By.name("frequency"))).selectByVisibleText(fq);
                Thread.sleep(3000);
                } catch (Exception e){
                    e.printStackTrace();
                }

                Thread.sleep(1500);

                try {
                    WebElement selectElement = driver.findElement(By.id("firstPeriod"));
                    Select select = new Select(selectElement);
                    List<WebElement> opts = select.getOptions();
------
-----
----
--
-

The problem is, when 'rt' equal to "Overlay Report", there are no element for this report to match the String in 'fq' array. Hence, it will proceed to the next code within the same loop.

How I can jump into the initial loop again which is,

for( String rt : rep_type ) {

so it will not proceed to the next code when there are no condition met with 'fq' array.

Aucun commentaire:

Enregistrer un commentaire