facebookarchive / WebDriverAgent

A WebDriver server for iOS that runs inside the Simulator.
Other
4.15k stars 1.37k forks source link

Scroll to element is not possible on iOS Simulator #971

Open mszumilas opened 6 years ago

mszumilas commented 6 years ago

Hi, I perform

By elementName = By.id("element"); RemoteWebElement element = (RemoteWebElement) driver.findElement(elementName); String elementID = element.getId(); HashMap<String, String> scrollObject = new HashMap<String, String>(); scrollObject.put("element", elementID); scrollObject.put("toVisible", "true"); driver.executeScript("mobile:scroll", scrollObject);

on the simulator with iOS 11.4. Application before running this method is in the view where element is present. I get this error:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Error Domain=com.facebook.WebDriverAgent Code=1 "Failed to find scrollable visible parent with 2 visible children" UserInfo={NSLocalizedDescription=Failed to find scrollable visible parent with 2 visible children} Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z' System info: host: 'My-Mac-mini.local', ip: '', os.name: 'Mac OS X', os.arch: '', os.version: '10.13.6', java.version: '10.0.1' Driver info: io.appium.java_client.ios.IOSDriver Capabilities {app: /Users/{username}/Docum..., browserName: , databaseEnabled: false, deviceName: iPhone Simulator, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: false, platform: MAC, platformName: iOS, platformVersion: 11.4, takesScreenshot: true, udid: AB2086DA-DA44-4CA8-B565-336..., webStorageEnabled: false} Session ID: 3c649cbd-706d-473d-87cc-a171d7ce9f96

Any help how to run this scroll?

sumanthvakacharla commented 5 years ago

Better to use touchActions than executeScript (element to element scrolling). Scroll is very slow or not at all working with some appium and Mac OS, Xcode combination of versions. But touchActions is also broken in 1.9.1 Appium Server with Appium Desktop 1.8.2 iOS 12 Mojave update and Xcode update 10.1 Better not to update. Android is super best in scrolling functionality, Don't know why Appium or Apple team is not taking at most care while rolling an update.

lubbo commented 5 years ago

But touchActions is also broken in 1.9.1 Appium Server with Appium Desktop 1.8.2 iOS 12 Mojave update and Xcode update 10.1 Better not to update.

Can you provide a related issue(s) to that problem? I actually can't scroll using any methods (scroll script, touchActions) on real device using Xcode 10.1 Mojave iOS 12 Appium 10

Result is no error but no scroll

Sumanth9318 commented 5 years ago

I have made a code to force scroll using execute script. That's working for me surprisingly. But touch actions is not working as expected

lubbo commented 5 years ago

I have made a code to force scroll using execute script. That's working for me surprisingly. But touch actions is not working as expected

It would be nice if you can provide that script! Thks

Sumanth9318 commented 5 years ago

class Scrolling():
    def scroll_to_element(self, element_name, direction = "down", click = False):
        visibility = False
        # Scroll until element is visible 
        while (visibility == False):
            try:
                # Trying to identify the element in first attempt
                destination_element = self.driver.find_element_by_name(element_name)
                self.test.wait(2)

                visibility = destination_element.is_displayed()
                # Add this condition as some elements are able to be identified by the driver but still are not visible.
                if not visibility:
                    raise Exception
            except:
                # Use execute script instead of TouchAction because TouchAction needs the element to be visible.
                self.driver.execute_script("mobile: scroll", {"direction": direction})

        if(click):
            destination_element.click()
        else:
            return destination_element