Reputation: 355
Hi I want to know how to scroll in appium using python
I have done it in Java before and it worked really well.
driver.scrollTo("Destination");
However I can't seem to do the same in python. I am fairly new to python and I have try doing multiple ways to scroll
One way I tried was
el1 = self.driver.find_element_by_name('Starting')
el2 = self.driver.find_element_by_name('Ending')
self.driver.scroll(el1, el2)
second way I tried was
self.driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("DesinationText").instance(0));').
second way scroll once but didn't scroll all the way down so it threw NoSuchElementException. Also, can someone explain to me what instances are in UiSelector? I read the description but I didn't quite understand
Instance: Set the search criteria to match the widget by its instance number.
Upvotes: 6
Views: 13055
Reputation: 486
self.driver.scroll(el1, el2)
is not working for me either.
I started using
self.driver.swipe(470, 1400, 470, 1000, 400)
driver.swipe(start_x, start_y, end_x, end_y, duration)
will be available in _touch.py file
Swipe down slowly, add a logic to check if the element is present - continue till the element is found.
Upvotes: 5
Reputation: 1
instance(i) is like index(i) but for some reason works better.
what is it used for? let's say that in the current activity we are testing (which is present on the screen), there are 10 TextView views. in that case the following selector:
new UiSelector().className("android.widget.TextView")
is a good match for all of the 10 TextView views we have on the screen, but if you don't specify exactly which instance\index you want to match, it will return the first one by default. But, let's assume you want to have a match specifically for the 10th TextView, just use the following selector:
new UiSelector().className("android.widget.TextView").instance(10)
The code you have written is good and is working. i have wrapped it up with example of how to handle errors:
def scroll_to_text(text):
try:
element = driver.find_element_by_android_uiautomator(
'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("'+text+'").instance(0));')
return element
except NoSuchElementException:
logger.error('it was not found')
return None
except Exception, e:
logger.error("Unexpected error:")
logger.exception(e)
return None
So I guess you have a different problem than what you thought originally. Please note:
Hope this helps. Gil.
Upvotes: -1
Reputation: 355
I ended up using coordinate even though its not the best solution it works for me at the moment
action = TouchAction(self.driver)
el = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, loc)))
action.press(el).move_to(x=10, y=-500).release().perform()
Upvotes: 4