Wait until specific value appears in selenium excel vba

血红的双手。 提交于 2020-01-25 10:56:06

问题


I have an element with this html

<span id="ContentPlaceHolder1_Label2" designtimedragdrop="1319" style="display:inline-block;color:Firebrick;font-size:Medium;font-weight:bold;width:510px;"></span>

and after clicking Save button on the page this part changes to that

<span id="ContentPlaceHolder1_Label2" designtimedragdrop="1319" style="display:inline-block;color:Firebrick;font-size:Medium;font-weight:bold;width:510px;">تم حفظ التعديل بنجاح</span>

You would notice this value تم حفظ التعديل بنجاح .. After that I should click another button but the problem appears when the internet connection is slow. I got the other button clicked before saving How can I wait for the appearance of the value تم حفظ التعديل بنجاح and then after the appearance of that text >> move to the another button

Thanks advanced for help


回答1:


I would re-write this as you risk an infinite loop. Make it a timed loop and add in a DoEvents.

Dim result As String, testElement As Object, t As Date
Const MAX_WAIT_SEC As Long = 10 '<==adjust time here
t = Timer
Do
    DoEvents
    On Error Resume Next
    Set testElement = .FindElementById("ContentPlaceHolder1_Label2")
    result = testElement.Text
    If Timer - t > MAX_WAIT_SEC Then Exit Do
    On Error GoTo 0
Loop While result <> "تم حفظ التعديل بنجاح"



回答2:


I have tried this solution and it worked well for me This was with the help of Ziggus' suggestion

        Do Until .FindElementById("ContentPlaceHolder1_Label2").Text = "تم حفظ التعديل بنجاح"
        Application.Wait Now() + TimeValue("00:00:01")
    Loop


来源:https://stackoverflow.com/questions/53891253/wait-until-specific-value-appears-in-selenium-excel-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!