等到元素存在 [英] Wait Until Element is Present

查看:82
本文介绍了等到元素存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在隐式等待中替换显式等待(Wait(20);)

我知道这是在selenium webdriver中实现的,我可以写这样的东西:



WebDriverWait wait = new WebDriverWait(driver,30);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(QUOT; ID1")));



但webdriver的但它确实使用硒不适合我。

谁可以帮我解决这个问题(如果没有立即可用,请等待一段时间才能找到一个或多个元素)?b




        private void CheckFindElement1()

        {

           试试


            {

                等待(20);

                VAR MLM = web_Browser.Document.GetElementById(QUOT; ID1");

             &NBSP ;  mlm.InvokeMember(" Click");

            }
            catch(例外)

            {

               等待(1);&
                CheckFindElement1();

            }
        }

I want to replace the explicit waits (Wait(20);) on implicit waits
I know that this is implemented in selenium webdriver, and I can write something like this:

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id1")));

but use selenium webdriver it does not suit me.
who can help me in solving this problem (wait for a certain amount of time to find an element or elements if they are not immediately available)?


        private void CheckFindElement1()
        {
            try

            {
                Wait(20);
                var mlm = web_Browser.Document.GetElementById("id1");
                mlm.InvokeMember("Click");
            }
            catch (Exception)
            {
                Wait(1);
                CheckFindElement1();
            }
        }

推荐答案

在我看来,确定性的方法是在创建元素时为元素添加一个onLoad处理程序。 这样,您就可以确切地知道它何时出现。
It seems to me the deterministic way to do this is to add an onLoad handler to the element when you create it.  That way, you'd know exactly when it shows up.


这篇关于等到元素存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆