2017-03-27 69 views
0

我嘗試使用下面的代碼滾動到一個元素:Appium-uiAutomator工作正常,爲Android而不是iOS的

@AndroidFindBy(uiAutomator = 「新UiScrollable(新UiSelector())scrollIntoView(」 + 「new UiSelector()。text(\」Contacts \「));」) @iOSFindBy(uiAutomator =「new UiScrollable(new UiSelector())。scrollIntoView(」+「new UiSelector()。text(\ 「));」) public MobileElement orgContact;

這完全適用於Android的,但在iOS上,我得到以下錯誤: org.openqa.selenium.NoSuchElementException:無法通過這一戰略定位的元素:定位地圖: - 本機內容:「By.IosUIAutomation:新的UiScrollable(new UiSelector())。scrollIntoView(new UiSelector().text(「Contacts」));「

我也曾嘗試使用滾動: 公共無效verticalScroll(AppiumDriver司機){

this.driver=driver; 
dimensions = driver.manage().window().getSize(); 
Double screenHeightStart = dimensions.getHeight() * 0.5; 
int scrollStart = screenHeightStart.intValue(); 
System.out.println("s="+scrollStart); 
Double screenHeightEnd = dimensions.getHeight() * 0.2; 
int scrollEnd = screenHeightEnd.intValue(); 
driver.swipe(0,scrollStart,0,scrollEnd,5000); 

} 但它也不起作用。 任何人都可以請建議我在這裏做錯了什麼

回答

0

沙洛姆Ronit。

您的代碼無法正常工作的原因是因爲您使用的Android定位器策略也適用於您@iOSFindBy這是錯誤的,非常錯誤。

根據您的Xcode版本,你可能無法使用UiAutomator在iOS(在Xcode 8蘋果刪除了此選項)

必須使用ID /輔助ID甚至Xpath的。請花點時間研究定位器策略,搜索示例以及如何正確查找iOS的元素。

我不能提供更多的幫助,因爲我不熟悉您嘗試自動化的應用程序。這個元素是否有ID?是可見的,或者您必須滾動才能找到它?你甚至知道如何使用driver.findBy()?