
我正在尝试运行命令以在模拟器上滚动屏幕.我尝试了Action类中的一组action命令,但是它们不一致.我最终偶然发现了下面的代码.
是否需要导入或包含某些内容才能使这些 *** 作正常运行?我的另一个困惑是,此代码在使用Espresso驱动程序时有效,但在Uiautomator2驱动程序下运行时却产生此错误消息.我尝试导入Action类,但这不能解决问题.同样,Uiautomator2驱动程序上是否需要导入或专门用于这些命令的内容?
此代码在使用Espresso驱动程序时有效,但在Uiautomator2驱动程序下运行时会产生此错误消息.我尝试导入Action类,但这不能解决问题.
WebElement element1 = wait.until(ExpectedConditions.visibilityOfElementLocated(originLocator));WebElement element2 = wait.until(ExpectedConditions.visibilityOfElementLocated(destinationLocator));int startY = element1.getLocation().getY() + (element1.getSize().getHeight() / 2);int startX = element1.getLocation().getX() + (element1.getSize().getWIDth() / 2);int endX = element2.getLocation().getX() + (element2.getSize().getWIDth() / 2);int endY = element2.getLocation().getY() + (element2.getSize().getHeight() / 2);Pointerinput input = new Pointerinput(Pointerinput.Kind.touch, "input");Sequence swipeto = new Sequence(input, 0);swipeto.addAction(input.createPointerMove(Duration.ZERO, Pointerinput.Origin.vIEwport(), startX, startY)); swipeto.addAction(input.createPointerDown(Pointerinput.Mousebutton.left.asArg()));swipeto.addAction(input.createPointerMove(Duration.ofMillis(1000), Pointerinput.Origin.vIEwport(), endX, endY));swipeto.addAction(input.createPointerUp(Pointerinput.Mousebutton.left.asArg()));driver.perform(Arrays.asList(swipeto));这应该在模拟器上滚动移动应用程序的可见页面,但是当前在使用Uiautomator2驱动程序运行时会导致以下错误(org.openqa.selenium.UnsupportedCommandException: *** 作).
编辑:从下面的注释中应用代码后,我得到以下代码,该代码始终与Uiautomator2驱动程序兼容,但与Espresso驱动程序不兼容(它在屏幕上定位了错误的空间,似乎点击了一个元素而不是触摸并按住) .
WebElement element1 = wait.until(ExpectedConditions.visibilityOfElementLocated(originLocator)); WebElement element2 = wait.until(ExpectedConditions.visibilityOfElementLocated(destinationLocator)); int startY = element1.getLocation().getY() + (element1.getSize().getHeight() / 2); int startX = element1.getLocation().getX() + (element1.getSize().getWIDth() / 2); int endX = element2.getLocation().getX() + (element2.getSize().getWIDth() / 2); int endY = element2.getLocation().getY() + (element2.getSize().getHeight() / 2); Dimension dim=driver.manage().window().getSize(); int height=(int) dim.getHeight(); int wIDth=(int) dim.getWIDth(); int x= wIDth/2; new touchAction(driver) .press(Pointoption.point(x,startY)) .waitaction(Waitoptions.waitoptions(Duration.ofMillis(2000))) .moveto(Pointoption.point(x,endY)) .release() .perform();所以我确实为每个驱动程序提供了一个工作版本.有谁知道为什么这些行为取决于所使用的驱动程序?
解决方法:
如果您想在androID应用上滚动,则可以使用触摸动作类.下面的代码将向下滚动.如果要向上滚动,请相应地更改startY和startX.希望能帮助到你.
public voID scrollDown() { Dimension dim=new Dimension(); int height=(int) dim.getHeight(); int wIDth=(int) dim.getWIDth(); int x= wIDth/2; int startY=(int) (height*0.80); int endY=(int) (height*0.20); new touchAction(driver).press(x, startY).waitaction(Duration.ofMillis(2000)).moveto(x, endY).release().perform(); } 总结 以上是内存溢出为你收集整理的Java-如何使用Android自动化修复“ UnsupportedCommandException: *** 作”错误全部内容,希望文章能够帮你解决Java-如何使用Android自动化修复“ UnsupportedCommandException: *** 作”错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)