appium version: V1.13.0
simulator android version: 9.0
i want to swipe in the specific area like below picture shows, and until the “edit” element is appear.
the target element is not in the current page, here is my codes, but swipe action doesn’t work.
touchAction is useless,too. cause element touch press is beyond this area.
String text = "your text"
WebElement el = driver.findElement(MobileBy
.AndroidUIAutomator("new UiScrollable(new UiSelector()).setAsVerticalList().scrollIntoView("
+ "new UiSelector().text(\""+text+"\"));")));
as far as you have several scroll views also better set scrollView ID:
String text = "your text"
WebElement el = driver.findElement(MobileBy
.AndroidUIAutomator("new UiScrollable(new UiSelector().resourceId(\"YOUR_RECYCLERVIEW_ID\")).setAsVerticalList().scrollIntoView("
+ "new UiSelector().text(\""+text+"\"));")));
@Aleksei thanks for reply first, i’ve tried your code, but it doesn’t work.cause it’s scroll the page vertically, all i want is swipe in that area horizontally
It will swipe whatever you asking it for! If on page several scroll views it will swipe whatever first which means random. So you need specify in such case scrollView element that needed to be swiped.
So in general you can specify view id, orientation (horisontal or vertical) and swipe direction. These all needed when view has several scrollViews - to help uiAutomator understand what is needed.
@Aleksei Thank you so much, it’s ok now, like you said before(method 2), i have to specify which element i need to swipe, use attribute like resource-id or className etc.
Hi @Aleksei I tried using the same command its swiping but instead of swiping down its swiping up . Is there is any way to say the direction in which it will swipe .
Code snippet:
MobileElement element = (MobileElement)getTLDriver().findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().resourceId(\"resourceId\")).setAsVerticalList().scrollIntoView("
+ "new UiSelector().text(\"Paragraph\"))"));
Thanks @Aleksei I have a doubt, the ListView I am trying to scroll has its scrollable value as ‘false’ does that got any impact with scrolling that Appium is trying to do ?
I get an InvalidArgumentException error: on my line driver.perform(Arrays.asList(dragNDrop));
I don’t understand why?
I don’t quite understand how it works and what needs to be indicated here:
MobileElement dragMe = (MobileElement) driver.findElementByAccessibilityId(“dragMe”);
MobileElement drop =(MobileElement)driver.findElementByAccessibilityId(“dropzone”);
What I wrote:
MobileElement dragMe = (MobileElement) driver.findElement(By.xpath(“//android.widget.TextView[contains(@text, ‘м. Дніпро, вул. Щукіна, буд. 1’)]”));
MobileElement drop =(MobileElement)driver.findElement(By.xpath(“//android.widget.TextView[contains(@text, ‘м. Дніпро, вул. Щукіна, буд. 1’)]”));
Point source = dragMe.getCenter();
Point target = drop.getCenter();
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence dragNDrop = new Sequence(finger, 1);
dragNDrop.addAction(finger.createPointerMove(Duration.ofSeconds(1),
PointerInput.Origin.viewport(), source.x, source.y));
dragNDrop.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
dragNDrop.addAction(finger.createPointerMove(Duration.ofSeconds(1),
PointerInput.Origin.viewport(),target.x, target.y));
dragNDrop.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
driver.perform(Arrays.asList(dragNDrop));