Try printing ( with log) the command you are trying to execute, run it in a seperate command line to see if it's working properly.
since it's related to input I am suspecting the problem is with the youtube url you are providing
Create a variable called "counter". Than use "is element exist" to check if element exist and update "counter" variable whenever element is missing. Check counter variable in the loop, and fail thread if "counter" hit 3
I think you could use another thread with the browser to accomplish this. And saving the necessary data to a resource / global variable, then using this data in the new thread, whether with the browser or whatever needs to be done.