appium / appium-xcuitest-driver

Appium iOS driver, backed by Apple XCTest
https://appium.github.io/appium-xcuitest-driver/
Apache License 2.0
749 stars 419 forks source link

Why a menu item is collapsing before it's child item is clicked in iOS only and how to prevent it ? #2472

Open PrasadNutalapati opened 1 month ago

PrasadNutalapati commented 1 month ago

I am working on mobileweb Selenium-Appium-Java test script development. The scenario is like this.

                //'Shop' menu item under hamburger menu in the mobile
waitingDriver.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//span[@class='toggle'])[2]"))).click();
                doWait(3000);
                // category item under 'Shop' menu item  
WebElement categoryElm = waitingDriver.until(ExpectedConditions.elementToBeClickable(By.xpath(String.format("//a[contains(text(),'%s')]",category))));
                doWait(3000);// sleep method
System.out.println("category Text="+categoryElm.getText()); // outputs Conduit
                elementActionsTap(categoryElm);
                if(null != sub_category) { 
                    // sub-category under category menu item
WebElement sub_categoryElm = waitingDriver.until(ExpectedConditions.elementToBeClickable(By.xpath(String.format("//a[normalize-space()='%s']",sub_category))));
System.out.println("sub_categoryElm Text="+sub_categoryElm.getText()); // supposedly output 'Steel Conduit'
                    elementActionsTap(sub_categoryElm);
                }   // end 'if' 

/**
* The Tap method using W3C Actions class.
*/

public void elementActionsTap(WebElement elm) {
    int elmCenterX = elm.getLocation().getX() + elm.getSize().getWidth()/2;
    int elmCenterY = elm.getLocation().getY() + elm.getSize().getHeight()/2;
    PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "indexFinger");
    Sequence tap = new Sequence(finger, 1);
    tap.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), elmCenterX, elmCenterY));
    tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
    tap.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
    driver.perform(List.of(tap));
}       
KazuCocoa commented 1 month ago

It looks like the app's implementation could affect the behavior. https://github.com/appium/appium-xcuitest-driver/blob/master/docs/guides/input-events.md is the implementation guide in Appium/WDA to emulate the click action. If the OS or the app's implementation possibly handled such touch events for multiple layers etc, the behavior maybe occur.

Checking the system log, page source or debugging the app's touch implementation would give more info I guess.