2

I am automating a Tablet application using Appium + Java. In a screen, I have 100+ fields (Textbox + Dropdown) to automate which has scroll view.

To automate those 100+ fields, I have listed down all the IDs(of those textbox and dropdown in that screen) along with the test Cases and Test Data in separate Excel sheets. My code runs in a loop, picks Test Case, its Data and relevant ID and executes. So, my code looks like:

    loop : for(int j = 1; j <= fieldCount; j++)
    {
        objElementRepositoryLibrary.setElementRepositoryDataLibrary(j);

        switch(ElementRepositoryLibrary.getElementType()) {

        case "AutoPopulated":
            System.out.println(ElementRepositoryLibrary.getElementValue() + " is Autopopulated");
            break;

        case "Dropdown": 
            ElementOperation.checkElementState(qdeDriver, ElementRepositoryLibrary.getLocator(), ElementRepositoryLibrary.getElementValue());

            if(ElementOperation.ElementAcceess.equals(false))
                System.out.println(ElementRepositoryLibrary.getElementValue() + " is disabled");
            else
                objElementOperation.dropdownSelectListner(qdeDriver, ElementRepositoryLibrary.getLocator(), ElementRepositoryLibrary.getElementValue(), field[0][j-1]);
            break;

        case "Button":
            ElementOperation.checkElementState(qdeDriver, ElementRepositoryLibrary.getLocator(), ElementRepositoryLibrary.getElementValue());

            if(ElementOperation.ElementAcceess.equals(false)) {
                System.out.println(ElementRepositoryLibrary.getElementValue() + " is disabled");
                break loop;
            }
            else if(field[0][j-1].equals(""))
                System.out.println("Checking for Null value");
            else if(field[0][j-1].equals("Yes") && ElementRepositoryLibrary.getFieldName().equals("QR Scanner"))
                objElementOperation.buttonClickListner(qdeDriver, ElementRepositoryLibrary.getLocator(), ElementRepositoryLibrary.getElementValue());
            else if(ElementRepositoryLibrary.getFieldName().contains("Capture Document"))
                objElementOperation.captureDocument(qdeDriver, ElementRepositoryLibrary.getLocator(), ElementRepositoryLibrary.getElementValue());
                break;

        default :
            objElementOperation.textboxSetListner(qdeDriver, ElementRepositoryLibrary.getElementType(), ElementRepositoryLibrary.getLocator(), 
                    ElementRepositoryLibrary.getElementValue(), field[0][j-1]);
            break;
        }   
    }

ISSUE: After filling few(say 7) fields, it is giving me NoSuchElementException because I have to scroll in the screen to move to the next fields(It goes like: screen contains 7 fields & you have to scroll to view the fields below and automator will nor recognize the element until it is viewed in the screen).

What I had tried is, I did catch for NoSuchElementException and performed Scroll operation. But it is not the proper way to do because if the element which has been searched is not present in actual, then also it will catch NoSuchElementException and perform scroll operation.

Suggest some good way to eliminate this issue. Let me know if any detail needed.

0

Scroll till the element having text. Try below code.

driver.scrollTo("Your partial text");

Approach 2:

isFoundElement = driver.findElements(myElement).size() > 0;
while (!isFoundElement) {
  // do something
}
  • First of all, scrollTo method has been depricated (Correct me if I am wrong), so I have created swipe operation which works fine. But the issue is, where should I put that method. – Ashish Mar 17 '17 at 6:31
  • Yes scrollTo method is depricated, you can try using element isDisplayed() method in condition loop instead of try catch? – zishan paya Mar 17 '17 at 6:51
  • added 2nd approach. This will not wait for implicit wait timeout and execution will be fast. Hope this help. – zishan paya Mar 17 '17 at 6:59
  • the way which you had given will work but in the circumstances that myElement should be know before execution. As you can see my code has loop, so I will not be certain that when and which element I should call for isFoundElement – Ashish Mar 20 '17 at 6:43
0

So, here is the answer to my question: Before starting switch case, I performed one check:

ElementOperation.checkElementAvailable(qdeDriver, ElementRepositoryLibrary.getLocator(), ElementRepositoryLibrary.getElementValue());
        if(ElementOperation.ElementAvailablity == true) {
            switch(ElementRepositoryLibrary.getElementType()) {
}

where checkElementAvailable is:

public static boolean checkElementAvailable(AndroidDriver<?> eleOpDriver, String locator, String elementValue) throws Exception {
    try {
        ElementAvailablity = findElement(eleOpDriver, locator, elementValue).isDisplayed();
        System.out.println("Element Availablity for " + elementValue + " is " + ElementAvailablity);
        }
    catch (Exception e) {
        System.out.println("General exception for " + elementValue);
        e.printStackTrace();
        }
return ElementAvailablity;
    }
  • Your code will work but in case if element is not displayed which you specified tin try block will keep on pooling the element till implicit wait. So before scrolling you wait time will be large. In my answer, if element is not available the final List will have null value, check the size and perform scroll. Correct me. – zishan paya Mar 23 '17 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.