如何在依赖于另一个下拉列表的selenium中添加显式等待?

时间:2017-02-15 10:36:23

标签: java selenium automation cucumber appium

如何使用selenium在下拉列表中添加显式等待,直到找到文本为止? UI

MY CODE

1 个答案:

答案 0 :(得分:2)

下面的代码将等到指定的文本不存在..

    int i=0;

    while(i==0)
    {
        try{
            Select select = new Select(driver.findElement(By.xpath("ELEMENT_XPATH")));
            select.getOptions().indexOf(0);
            int ed = select.getOptions().indexOf(0);
            if(ed==0); //check whether it's got your index or not(if not then it will throw error and go to Catch section)
            {
                System.out.println("Pass got.. Index Value");
            }
            i=1; //if it got your index value in drop down then .. exit from loop..
        }catch(org.openqa.selenium.NoSuchElementException NSEE)
        {
            i=0; // iteration will continue until .. you'll not get your index in Drop down.. 
        }
    }