How to automate actions in certain apps?
By default regular Apps can't control other apps. 

There are two exceptions:


If the app is a system app (signed with the same cryptographic key that was used to sign the OS itself)
An app can request access to the "accessibility services". Using this service  an app can interact with other apps.


Note that Google is currently (mid 2018) restricting the accessibility service usage. Only apps that use it for legitimate purposes are allowed (helping disabled people to use an Android phone. As you can imagine controlling third party apps is not a legitimate purpose for Google's perspective.