Reputation: 21
Using Appium and Desired capability,i am launching android application in device,but unable to navigate to elements which are not in screen view of the same page, JavascriptExecutor is also not compatible with appium code.I have used UIAutomator viewer to identify objects.But only the objects which are in screen view will be identified.Some how we need to scroll down,to the end to identify the objects,but JavascriptExecutor is also not compatible with appium code,and using Keys.END and Keys.ARROW_DOWN also I am unable to identify object which are not in screen view of the same page.
Upvotes: 2
Views: 1429
Reputation: 565
Kindly use a combination of swiping down to make an element visible before interacting with it. Code Example - HashMap swipeObject = new HashMap();
WebElement we = driver.findElement(By.xpath("/relative"));
Dimension screenSize = driver.manage().window().getSize();
Double screenWidth = Double.valueOf(String.valueOf(screenSize.getWidth())) / 2;
Double screenHeight = Double.valueOf(String.valueOf(screenSize.getHeight())) / 2;
swipeObject.put("startX", (screenWidth));
swipeObject.put("startY", screenHeight + 100);
swipeObject.put("endX", (screenWidth));
swipeObject.put("endY", (screenHeight));
swipeObject.put("duration", 1.0);
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
while (!elementPresent(driver,by, 2)) {
js.executeScript("mobile: swipe", swipeObject);
Thread.sleep(1000);
}
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
Upvotes: 1
Reputation: 901
Swipe should work for you now with the latest Appium. If you want to get creative and have it scroll in specific areas that is a little more work but here is a java snippet to get started.
public void swipe(Double startX, Double startY, Double endX, Double endY, Double duration) {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> swipeObject = new HashMap<String, Double>();
swipeObject.put("startX", startX);
swipeObject.put("startY", startY);
swipeObject.put("endX", endX);
swipeObject.put("endY", endY);
swipeObject.put("duration", duration);
js.executeScript("mobile: swipe", swipeObject);
}
Android does not have a different between when an element is present or visible. Either they are both true or false. iOS on the other hand knows when things are just out of view and invoking a click/tap on them will auto scroll to perform the action. This makes it a little harder to write tests and you will always need to scroll and then check if it is there before doing the next action.
Upvotes: 0
Reputation: 21
Actually my question was how to scroll down in device.I am already using UIautomatorviewer. But in device only elements within screen view could be identified.Emulator it work fine if the screen of the application fits the emulator size,if emaulator size is reduced.again objects out of view within the screen could not be identified.JavascriptExecutor is also not compatible with appium code,and using Keys.END and Keys.ARROW_DOWN also I am unable to identify object which are not in screen view.Please some one know how to do this.
Upvotes: 0
Reputation: 21
1) Goto Android sdk folder --> Tools --> Execute uiautomatorviewer.bat 2) Once UI Automator viewer is launched, click device icon 3) Now you can view the properties of the application screen captured page Note: Using UI automator, You can view the properties only in screenshot method
Upvotes: 0