flutter:scrollIntoView not working
Hello,
I am trying to scroll on a mobile flutter app, to a specific button, to be able to tap on it.
Using python 3.10, Appium v2.0.0-beta.71, [email protected]
I am using the following code, where 'keyValueString' is the key of the button:
self.driver.execute_script('flutter:scrollIntoView', { 'finderType': 'ByValueKey', 'keyValueString': key, 'alignment': 0.5, })
I receive this error: "error: Cannot read properties of undefined (reading 'alignment')") payload = ('{"value":{"error":"unknown error","message":"An unknown server-side error ' 'occurred while processing the command. Original error: Cannot read ' 'properties of undefined (reading 'alignment')","stacktrace":"UnknownError: ' 'An unknown server-side error occurred while processing the command. Original ' "error: Cannot read properties of undefined (reading 'alignment')\n at " 'getResponseForW3CError '
and this is the log from Appium:
HTTP] --> POST /session/68d2391d-37ab-4dfd-ab15-97d853eeb269/execute/sync
[HTTP] {"script":"flutter:scrollIntoView","args":[{"finderType":"ByValueKey","keyValueString":"GuestWifi_settings_button_Copy_Password","alignment":0.5}]}
[debug] [FlutterDriver@e821 (68d2391d)] Calling AppiumDriver.execute() with args: ["flutter:scrollIntoView",[{"finderType":"ByValueKey","keyValueString":"GuestWifi_settings_button_Copy_Password","alignment":0.5}],"68d2391d-37ab-4dfd-ab15-97d853eeb269"]
[debug] [FlutterDriver] Executing Flutter driver command 'execute'
[debug] [FlutterDriver@e821 (68d2391d)] Encountered internal error running command: TypeError: Cannot read properties of undefined (reading 'alignment')
[debug] [FlutterDriver@e821 (68d2391d)] at scrollIntoView (/Users/devolo/.appium/node_modules/appium-flutter-driver/lib/commands/execute/scroll.ts:212:11)
[debug] [FlutterDriver@e821 (68d2391d)] at FlutterDriver.execute (/Users/devolo/.appium/node_modules/appium-flutter-driver/lib/commands/execute.ts:60:28)
[debug] [FlutterDriver@e821 (68d2391d)] at commandExecutor (/Users/devolo/node_modules/@appium/base-driver/lib/basedriver/driver.ts:107:18)
[debug] [FlutterDriver@e821 (68d2391d)] at /Users/devolo/node_modules/async-lock/lib/index.js:171:12
[debug] [FlutterDriver@e821 (68d2391d)] at AsyncLock._promiseTry (/Users/devolo/node_modules/async-lock/lib/index.js:304:31)
[debug] [FlutterDriver@e821 (68d2391d)] at exec (/Users/devolo/node_modules/async-lock/lib/index.js:170:9)
[debug] [FlutterDriver@e821 (68d2391d)] at AsyncLock.acquire (/Users/devolo/node_modules/async-lock/lib/index.js:187:3)
[debug] [FlutterDriver@e821 (68d2391d)] at FlutterDriver.executeCommand (/Users/devolo/node_modules/@appium/base-driver/lib/basedriver/driver.ts:123:39)
[debug] [FlutterDriver@e821 (68d2391d)] at runMicrotasks (
I don't using python but I think it must {'alignment': 0.5}
Yes, it should be without the comma. But still, the error I receive is the same.
Could below work?
button_finder = finder.by_value_key("GuestWifi_settings_button_Copy_Password")
self.driver.execute_script('flutter:scrollIntoView', button_finder, {'alignment': 0.5 })
@KazuCocoa I tried the following codes in Java it doesn't seem to work if the element is not in the current view of the screen at all
** Code 1 **
Map<String, Object> params = new HashMap<>(); params.put("alignment", 0.5);
driver.executeScript("flutter:scrollIntoView", this.finder.byValueKey("item_12") , params);
** End of Code 1 **
And this code too
** Code 2 **
driver.executeScript("flutter:scroll", this.finder.byValueKey("item_12"), new HashMap<String, Object>() {{ put("dx", 90); put("dy", -400); put("durationMilliseconds", 300); put("frequency", 30); }});
** End of Code 2**
In Java, below works for me
WebElement scrollToElement = finder.byText(elementTextValue);
Map<String, Object> scrollParams = new HashMap<>();
scrollParams.put("item", scrollToElement);
scrollParams.put("dxScroll", 0); // Horizontal offset
scrollParams.put("dyScroll", -400); // Vertical offset
scrollParams.put("waitTimeoutMilliseconds", 10000); // Timeout (10 seconds)
driver.executeScript("flutter:scrollUntilVisible", finder.byType("ListView"), scrollParams);