Appium ios 隱式等待

selenium之ExpectedConditions類
??以前使用eclipse感覺不是很習慣,現在使用intelliJ IDEA編寫代碼。下面的是ExpectedConditions類下的一些方法,使用IDEA時會有方法提示。


??下面的是我自己根據實際工程中遇到的問題寫的一些方法

import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public IOSElement findElementByName(String name) {
        IOSElement button = (IOSElement) new WebDriverWait(driver, 30)
                .until(ExpectedConditions.visibilityOfElementLocated(By.name(name)));
        return button;
    }

??這段代碼實現的功能是設立一個顯式等待時間30秒,如果在30秒內找到這個元素,就返回IOSElement類型的元素。然后接下來就可以對這個元素進行操作。

 public List<IOSElement> findElementsByClassName(String className){
        List<IOSElement> elements = (List)new WebDriverWait(driver, 30)
                .until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(className)));
        return elements;

??這段代碼返回同一個界面上的所有的具有相同classname的元素。

  public IOSElement findElementByClassName(String ClassName,int i){
        List<IOSElement> Element = (List)new WebDriverWait(driver, 30)                .until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className(ClassName)));
        return Element.get(i);
    }

??這段代碼以上段代碼為基礎,比如要取到具有相同classname列表中所有元素中的第i個元素,就可以使用Listget方法,get(i)取到列表中索引值為i的對象。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容