All you need to do is feed it two webdriverobjects, it seems to do the rest. But I haven’t fully validated it works in all of my scenarios, that it can scroll down as well as up, that it doesn’t over-scroll, etc.
It doesn’t look like Android will ever provide page_source that contains out-of-view elements, including after you scroll (items at the top of the page are now out-of-view after a scroll and are dropped from XML). So there’s going to have to be some pretty clever functions coded to support all of the various scrolling I will need to do.
For example, many of my tests need to count the number of rows //android.widget.ListView/android.widget.LinearLayout in my view to make sure it matches summary counts elsewhere in the app. I’m going to need to scroll, count up the visible rows, scroll more, count up the visible rows making sure not to count ones already counted (guess I’ll have to keep track of some hopefully visible unique identifier in each row), and stop counting once the list has beens scrolled (again keeping track of hopefully visible unique identifier and stop scrolling once no new uniques appear after a scroll). It all seems overly complicated. I’d think by now these would be basic functions provided by Appium.
I’m hoping someone with more experience will chime in with the “best” way to do this.
scrollTo is only implemented in the iOS native context. I haven’t personally attempted scrolling in iOS WebView at this time.
You can try: "mobile: scroll" in the Webview. I don’t have more specific details, unfortunately.
According this: https://github.com/appium/appium/issues/3974 the answer is: “…the correct way to achieve what you want is to use mobile: scroll and then check that the element in question is within the bounds of the viewport.”
Traceback (most recent call last):
File “appium_test.py”, line 27, in
action.press(el).move_to(x=10, y=-500).release().perform()
File “C:\Python27\lib\site-packages\appium\webdriver\common\touch_action.py”, line 94, in perform
self._driver.execute(Command.TOUCH_ACTION, params)
File “C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 196, in execute
self.error_handler.check_response(response)
File “C:\Python27\lib\site-packages\appium\webdriver\errorhandler.py”, line 24, in check_response
super(MobileErrorHandler, self).check_response(response)
File “C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 103, in check_response
status = value[‘status’]
TypeError: string indices must be integers
def test_swipe(self):
x = []
sleep(1)
self.driver.find_element_by_name(“Views”).click()
sleep(1)
while x == []: #Perform below till i get the desired item which i am looking for. In this case the item is in second page
x = self.driver.find_elements_by_name(“Grid”)
if x == []: #Perform the scroll only if not able to locate the desired item in current screen
size = self.driver.get_window_size()
starty = int(size[“height”] * 0.80)
endy = int(size[“height”]*0.20)
startx = int(size[“width”]/2)
sleep(2)
self.driver.swipe(startx, starty, startx, endy, 3000) #Swipe from bottom to top
sleep(2)
else:
pass
sleep(1)
x[0].click()
Remove these lines from your code:
self.driver.scroll(el1, el2)
touch = TouchAction(self.driver)
touch.press(el1).wait(ms).move_to(el2).release().perform()
And just try using the below for iOS app:
el = self.driver.find_element_by_xpath('xpath_value')
self.driver.execute_script('mobile: scroll', {"element": el, "toVisible": True})
If you still see error message can you share your logs here. Try if you can use id instead of xpath