You can use tools specifically designed for this purpose.
A popular solution is Symfony's Panther library.
Given the page you are trying to get content for is hosted at http://example.com, and an element with the id "myElement" is added to the page using javascript (indicating the javascript we are dependent on has finished executing),
we could run the following code:
$client = \Symfony\Component\Panther\Client::createChromeClient();
$crawler = $client->request('GET', 'http://example.com');
$client->waitFor('#myElement');
var_dump($crawler->html());