2016-11-16 51 views
0

我試圖訪問一個容器,它有多個ID與它的內部,但我似乎無法讓它像我這樣做的Android的。Xpath與Appium iOS的容器與多個元素

這是我到目前爲止有:

try { 
     WebDriverWait wait = new WebDriverWait(driver, 3); 
     wait.until(ExpectedConditions.visibilityOfElementLocated(
       By.xpath("//UIACollectionCell[UIAStaticText[contains(@name, 'section')] and UIAStaticText[contains(@name, 'title')]]") 
     )); 
     System.out.println("xpath w/ ids found"); 
    } catch (Exception e){ 
     System.out.println("xpath w/ ids not found"); 
    } 

但它的正常工作,如果我只有一個文本在它

try { 
     WebDriverWait wait = new WebDriverWait(driver, 3); 
     wait.until(ExpectedConditions.visibilityOfElementLocated(
       By.xpath("//UIACollectionCell/UIAStaticText[contains(@name, 'section')]") 
     )); 
     System.out.println("xpath w/ ids found"); 
    } catch (Exception e){ 
     System.out.println("xpath w/ ids not found"); 
    } 

看來,使用[]我的容器使它由於某種原因無法理解...

任何想法?

謝謝!

+1

您是否也可以提供頁面XML以驗證XPath匹配? –

+0

xml元素是正確的,因爲它對一個元素有效。 只有當您需要一個包含多個文本的collectionCell時纔會出現此問題。 – user3718160

+0

如果我沒有XML上下文,我無法理解您的定位器。 –

回答

0

只是嘗試這樣的:

By.xpath("//UIACollectionCell[UIAStaticText[contains(@name, 'section') and contains(@name, 'title')]]"); 

希望這可以幫助,讓我知道會發生什麼。

+0

我不想要'Or'而只是'And'語句。我希望它有2個staticText 1,其中包含'section'&1,其中包含'標題' – user3718160

+0

因此使用而不是或 – noor

+0

這不起作用,因爲您要搜索包含'section'和'title'的UIAStaticText,這是不可能的。它是一個UIACollectionCell,其中包含2個UIAStaticText和'section',1和'title' – user3718160

0

它不工作,因爲您要求驅動程序等待單個元素。如果你想等幾個,那麼你必須使用ExpectedConditions.visibilityOfAllElementsLocatedBy(By)函數。

+0

它應該工作。它應該給1個元素UIACollectionCell(包含2個UIAStaticText「),但它仍然是1個元素 – user3718160

+0

By.xpath(」// UIACollectionCell [UIAStaticText [contains(@name,'section')]和UIAStaticText [contains(@name, 'title')]]「)'返回包含1個或更多'UIAStaticText [包含(@name,'title')並且包含(@name,'section')]'' –

+0

'Byxxpath(」/UIACollectionCell/UIAStaticText [contains(@name,'section')]「)'返回所有'UIAStaticText',其屬性'name'包含'section'。 –