How to get a Selenium/Ruby bot to wait before performing an action?

前端 未结 7 822
Happy的楠姐
Happy的楠姐 2020-12-16 21:28

I\'m building a Selenium/Ruby web bot that clicks on elements. The problem is, sometimes there isn\'t enough time for the page to load before the bot decides it can\'t find

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 22:10

    You can also simply use sleep(#) this will cause it to wait, and depending on your editor you can see which variations you can use so instead of seconds you can go to something lower or higher, in Ruby you don't even have to declare it.

    Just type sleep and a number in the parenthesis and you should see it stop for that amount of time in seconds, others note why this is a solution that might not be optimal, but if you only need it to wait for a bit on a page that will never take that long it's great one line code to use.

提交回复
热议问题