For the pop-up window you'll actually need to switch to a new window/pop-up/iframe that appears and you can do that with selenium window handling you can go through new windows, pop-ups, alerts and all.
You can start learning about the window handling just check here
Then after you switched to the new window just take the screenshot.
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.apache.commons.io.FileUtils;
WebDriver driver = new FirefoxDriver();
driver.get("https://www.wikipedia.org/");
/* Here we would have the switching to the new pop-up window (Window handling) code */
File file = ((TakeScreenshot) driver).getScreenshotAs(OutputType.FILE);
try{
FileUtils.copyFile(file, new File(location_for_the_file));
}
catch(IOException e){
e.printStackTrace();
}
If you are still having problems you can check java example and
here as a python example .