How to place a wrapfigure on top of the page?
If you let tex page break normally and note where it breaks the page you can force a "hidden" paragraph break at exactly that spot and insert th ewrapfig:
\documentclass{article}
\usepackage{graphicx,wrapfig}
\begin{document}
\section{aaa}
aaaa
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
\rule{1cm}{15cm}
\section{bbbb}
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four{% tex broke the page here!!!!
\parfillskip=0pt
\parskip=0pt
\par}
\begin{wrapfigure}{R}{0.5\textwidth}
\centering
\includegraphics[width=.5\linewidth]{example-image}
\caption{zzz}
\end{wrapfigure}
\noindent five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
\end{document}
Of course, you still have to count lines this way.
\documentclass{article}
\usepackage{graphicx}
\usepackage{afterpage}
\usepackage{caption}
\usepackage{showframe}
\begin{document}
\section{aaa}
aaaa
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
\rule{1cm}{15cm}
\afterpage{\hfill\raisebox{-\height}[0pt][0pt]%
{\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=.5\linewidth]{example-image}
\captionof{figure}{zzz}
\end{minipage}}\vspace{-\baselineskip}}
\section{bbbb}
\hangindent=\dimexpr -0.5\textwidth-\columnsep\relax
\hangafter=2
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
\rightskip=\dimexpr 0.5\textwidth+\columnsep\relax
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
\rightskip=0pt
\hangindent=\dimexpr -0.5\textwidth-\columnsep\relax
\hangafter=-1
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
one two three four five six seven eight nine ten
\end{document}