Selenium Wait doesn't wait for Element to be Clickable

核能气质少年 提交于 2019-12-05 12:13:20

It turns out that an event was being bound to the button after the button was dynamically added to the page. So the button WAS being clicked but nothing was happening. The sleep thread being placed in the code was just giving the client side event time to be bound.

My solution was to click the button, check for the expected result, and then repeat if the expected result wasn't in the DOM yet.

Since the expected result was for a form to open I polled the DOM like this:

button.Click();//click button to make form open
        var forms = Driver.Instance.FindElements(By.Id("inspectionDetailsForm"));//query the DOM for the form
        var times = 0;//keep tabs on how many times button has been clicked
        while(forms.Count < 1 && times < 100)//if the form hasn't loaded yet reclick the button and check for the form in the DOM, only try 100 times
        {

            button.Click();//reclick the button
            forms = Driver.Instance.FindElements(By.Id("inspectionDetailsForm"));//requery the DOM for the form
            times++;// keep track of times clicked
        }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!