If you find you're thinking too much while on an Expect project, give autoexpect a chance to be your friend.
A large number of tutorials on Expect have been published over the last decade. Among those available online are
[ Category Expectdfd ]