How to use watir-webdriver to wait for page load

后端 未结 7 1854
后悔当初
后悔当初 2021-02-01 21:34

Using watir-webdriver, how do I wait for a page to load after I click a link?

At the moment I am using:

sleep n

But this is not ideal a

7条回答
  •  -上瘾入骨i
    2021-02-01 22:12

    I had the same problem, and I tried to fix it by combining wait_until_present and

    until browser.div(:id=>"some_div").exists? do sleep 1 end
    

    tricks povided by @marc:

    some_div = browser.div(:id => 'some_div')
    
    begin 
    
      Watir::Wait.until
        some_div.visible?
      end
    
    rescue Watir::Wait::TimeoutError
    
      until some_div.visible?
        sleep 1
      end
    end
    

    Notice that it is your own responsibility to make sure that

    div(:id => "some_div")
    

    does exist.

提交回复
热议问题