How did Elijah know that he was about to be taken by God?
How did Elisha know this was going to happen?
I could not find anything prior to 2 Kings 2:1 when Scripture states that Elijah was going to be taken up, and 2:9 when Elijah asks what he can do for Elisha before he is taken.
Scripture does not say. The closest thing we get is this:
and Jehu the son of Nimshi you shall anoint king over Israel; and Elisha the son of Shaphat of Abel-meholah you shall anoint as prophet in your place. —1 Kings 19:16 NASB
God tells Elijah to anoint Elisha in his place, implying that it would not be long before Elijah was finished with his time as God's prophet. I found this commentary that mentions Elijah knew beforehand, but I could not find a Scriptural reference.
This is a prophetic event, a type and a foreshadowing.
Elijah is Christ and Elisha the disciples.
Do the disciples see Christ caught up to heaven? Yes.
They also get the double portion of the first born just like Elisha gets the mantle and the double portion from his master.
Does Elijah know that is going to be taken up to heaven? Yes.
Christ knows he was going to be taken to heaven and so does Elijah.