It's part timing, part cajoling and part luck.
I don't know the specific laws for other countries, but in the UK, children under 5 can only be "at work" for a maximum of 5 hours a day, between 9.30 and 4.30. This is from the moment they arrive into costume or hair/makeup at base, not when they get to set.
One child takes at minimum two, if not three or four, supervising adults - a chaperone (a professional who does this for a living), and one or two parents, who usually have not a clue what's going on. A lot of the day is spent keeping the parents fed, watered and amused as they look after the child, meaning a runner will often be assigned to them too, to fetch and carry. This small entourage will move as a single unit for the whole day.
The child is only allowed to be on set for 30 minutes at a time, with a total maximum of 2 hours on set per day. Additional breaks can be taken at the request of the chaperone or parent.
So, you bring the child in at the very last possible moment, onto a set with perhaps 100 other people - total strangers to the child. Also bear in mind that the set might be an ordinary living room... which only has three walls and a whole gantry of lights above an open ceiling... built from plywood in a massive open space which is mostly otherwise in darkness; vaguely revealing other strange wooden boxes off in the distance. Not exactly an ordinary situation to be thrust into.
If there was time, they have been introduced and had a little 'getting-to-know-you' time with the principal actor they need to interact with.
You then have 30 minutes to get them to do the one thing they are needed for, in sync with any other relevant action and dialog the adults need to perform.
You cannot overrun. Someone will be timing this to the absolute second, from the time they entered the studio. This is serious.
It can take something like a minute or more to get from everyone ready to go to actually calling "Action". All the precursor of calling the roll, hearing everyone's 'rolling/speed' responses from camera and sound, slating each camera, getting the camera op's opening shot 'set' and then all you need is the kid to behave for just 3 seconds… on cue.
Anyone who thinks a child under 3 will concentrate for the 3 seconds they appear in close-up hasn't actually tried to do this when there are 100 cast and crew around them, with some poor, overworked chaperone and the kid's mum, waving teddies and forced-cheerfully shouting "Over here, cherub! Look at the bunny!" in an increasingly frustrated manner... whilst the crew just keeps on rolling, in the hope they'll get one eventually.
A couple of pics of random sets - just to give an idea of how daunting it may be for a small child thrown into this situation. Movie sets do not meet anyone's definition of 'normal'. An adult will rapidly acclimatise, a child less-so.
There's too many people, too much dark; you can't see out past the lights, too much weird, too much distraction.
Source: https://medium.com/@mchetwalker/what-is-the-essential-role-played-by-a-focus-puller-on-a-film-set-87cd338c32ce
Source: https://film.utah.gov/blog/green-production-disney-andi-mack/
...and all this is after the journey they took to even get to set - this Daily Mail article from a few years ago has some aerial shots of some of the large London studios. It can be 10 minutes' drive from one side to the other. Can you imagine one minute you're walking through what looks like a field of scaffolding poles, then you're in King Arthur's castle...