2016-08-19 66 views
0

中的給定搜索參數無法在頁面上找到元素嘗試在Browserstack-cloud中自動執行iPad模擬器上的測試。例外:使用Appium

例外:一個元素找不到使用給定的搜索頁面上的參數

因爲我試過很多變種我,我試過有以下例外破壞許多定位策略很確定,我的錯誤是一個普遍的錯誤 - 但我找不到它。我的C#代碼:

DesiredCapabilities capabilities = new DesiredCapabilities(); 
capabilities.SetCapability("device", "iPad Air 2"); 
capabilities.SetCapability("browserstack.user", browserStackUser); 
capabilities.SetCapability("browserstack.key", browserStackKey); 
capabilities.SetCapability("name", "ios - actions"); 

Uri serverUri = new Uri("http://hub.browserstack.com/wd/hub/"); 
AppiumDriver<IWebElement> driver = new IOSDriver<IWebElement>(serverUri, capabilities, new TimeSpan(1000000000000)); 
driver.Navigate().GoToUrl("http://www.amazon.de"); 
driver.Context = "NATIVE_APP"; 
Thread.Sleep(20000); 
IWebElement anyElement = driver.FindElementByName("field-keywords"); 

該方法的一般錯誤是什麼?

這是我嘗試找到元素: amazon appium example

回答

1

能否請您上傳截圖,這樣我可以給你定位策略使用。此外,而不是GoToUrl,你可以使用get API。下面的代碼是用java編寫的。

driver.get(""http://www.amazon.de"); 
WebDriverWait wait = new WebDriverWait(driver, 30); 
wait.until(ExpectedConditions.presenceOfElementLocated(BY-LOCATOR-STRATEGY-HERE)); //wait for page to load before finding any element 
WebElement element = driver.findElement(BY-LOCATOR-STRATEGY-HERE); 
+0

我添加了屏幕截圖。定位器策略是按名稱。 –

+0

@ projekt-fisch:我沒有使用瀏覽器堆棧來實現自動化。但是,因爲這是瀏覽器,所以你的上下文不能有NATIVE_APP。此上下文用於本機應用程序。 您的測試是否啓動瀏覽器並打開亞馬遜網站?如果是,那麼你可以添加一個亞馬遜標誌等待語句,然後點擊搜索欄。 **'wait.until(ExpectedConditions.presenceOfElementLocated(By.id(「nav-logo」))); driver.findElement(By.id(「twotabsearchtextbox」))。sendKeys(「TEXT-TO-SEARCH」); ** ** – Suman

+0

thx。你的答案是「普通」瀏覽器自動化的方向。但我需要在iPad模擬器上找到元素。 –