适用于Android的Appium中的WebView的ScrollTo和ScrollToExact等效项 [英] ScrollTo and ScrollToExact equivalent for webView in appium for android
问题描述
我正在使用appium(java)自动化android应用程序.
要在本机组件上滚动,我使用scrollTo()
和scrollToExact()
方法.
但是在应用程序内使用webView的情况下;这些方法不起作用.
更新:
我也尝试了这两种方法:
I am automating android app using appium (java).
For scrolling on native components, I use scrollTo()
and scrollToExact()
methods.
But in case of webView inside the app ; these methods are not working.
UPDATE:
I have tried these two methods also:
public static void scrollNavigation(AppiumDriver<MobileElement> wd, String widID, String target, String direction)
{
JavascriptExecutor js = (JavascriptExecutor) wd;
HashMap<String, String> swipeObject = new HashMap<String, String>();
swipeObject.put("text", target);
swipeObject.put("direction", direction);
swipeObject.put("element", widID);
js.executeScript("mobile: scrollTo", swipeObject);
wait(200);
}
public static void swipeUpElement(AppiumDriver<MobileElement> driver, MobileElement element, int duration)
{
int topY = element.getLocation().getY();
int bottomY = topY + element.getSize().getHeight();
int centerX = element.getLocation().getX() + (element.getSize().getWidth()/2);
driver.swipe(centerX, bottomY, centerX, topY, duration);
}
但是在这两个方面我都需要元素-但是在页面上我找不到除Webview之外的任何元素.
我正在使用UiAutomator捕获ID.
任何建议/链接/解决方法都会有所帮助>
But in both these I need element- but on the page I cannot find any element except the webview.
I am using UiAutomator to capture the IDs.
Any suggestions / link / workaround will be helpful
推荐答案
在网络视图中唯一替换的元素.您需要开发数学逻辑来获取屏幕尺寸并根据其滚动,请使用以下代码,
ELements arent displaced uniquely in web view. U need to develop mathematical logic to get screen size and scroll according to them, use the below code,
public void scroll() throws IOException {
try {
Dimension dimensions = driver.manage().window().getSize();
System.out.println("Size of Window= " +dimensions);
int scrollStart = (int) (dimensions.getHeight() * 0.5);
System.out.println("Size of scrollStart= " +scrollStart);
int scrollEnd = (int) (dimensions.getHeight() * 0.2);
System.out.println("Size of cscrollEnd= " + scrollEnd);
driver.swipe(0,scrollStart,0,scrollEnd,1000);
Application_Log.info("Screen Swiped " );
} catch (IOException e) {
Assert.fail("Swipe failed");
}
}
这篇关于适用于Android的Appium中的WebView的ScrollTo和ScrollToExact等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!