VBA & Internet Explorer Automation: How do I get Vba to WAIT after it clicks a link

pivotpp

New Member
Joined
Jun 23, 2017
Messages
12
For example, I'm on yelp and search for 'burgers' in 'maine'




I have a for loop to scrape each of the 10 results and then click the link to get the next 10, until page 5 (so 50 results in total)




I run into a problem at number 11 (where page 2) would start.




I think a the source of the problem is that it would click 2 button and start scraping before it loads.




Code below:




This clicks the 'next' button on yelp



Code:
    ie.document.getelementsbyclassname("pagination-label responsive-hidden-small pagination-links_anchor")(0).Click

followed by 'wait until the page load':




Code:
    Do Until (ie.readyState = 4 And Not ie.Busy)
    DoEvents 
    Loop





However even with the do until ie. readystate = 4 as I pasted above --- it is actually NOT waiting.






Been looking into this for hours, this happens when I scrape google, and click the next button to go to page 2 as well. Any suggestions much appreciated.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
This is a stab in the dark, but maybe pause the code for a second before checking the ie.ReadyState.

Code:
ie.document.getelementsbyclassname("pagination-label responsive-hidden-small pagination-links_anchor")(0).Click

[B]Application.Wait Now + TimeValue("00:00:01")  [COLOR=#008000]'Pause one second[/COLOR][/B]

    Do Until (ie.readyState = 4 And Not ie.Busy)
    DoEvents 
    Loop
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,732
Messages
6,126,540
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top