TITLE: Find an element of order $p$ in a non-abelian group $G$ of order $p^3$ where $p$ is an odd prime
QUESTION [6 upvotes]: Problem. Let $p$ be an odd prime and $G$ be a non-abelian group of order $p^3$. Suppose there exists an element $x\in G$ of order $p^2$. Find an element $y\in G\setminus\langle x\rangle$ of order $p$.

It is true, by Cauchy's theorem or some other theorems, that $G$ has an element of order $p$. However, we are not sure whether it lies in $\langle x\rangle$ because $x^p,x^{2p},\ldots,x^{(p-1)p}$ all have order $p$.
I tried another approach: The number of element in $G$ of order $p^2$ must be a power of $$\varphi(p^2)=p(p-1),$$ where $\varphi$ is the Euler's totient function. There are $p^3-1$ non-identity elements in $G$. We have $$p^3-1=p(p-1)(p+1)+p-1=(p+1)\varphi(p^2)+p-1.$$ This also implies that $G$ has an element of order $p$, but the remainder $p-1$ is problematic as we already have $p-1$ elements of order $p$ above.
Does anyone have good ideas on this question?

REPLY [4 votes]: In a nonabelian group of order $p^3$, we must have $[G,G] = Z(G)$ and $|Z(G)|=p$.
So, for any $a,b \in G$, using $ba= ab[b,a]$, and $[b,a] \in Z(G)$, we get $(ab)^p = a^pb^p[b,a]^{p(p-1)/2} = a^pb^p$, since $p$ is odd.
Let $y \in G \setminus \langle x \rangle$. Then, since $G$ is nonabelian, $y$ cannot have order $p^3$, so $y^p =x^{ap}$ for some $a$. Then $(x^{-a}y)^p = x^{-ap}x^{ap}=1$, so $x^{-a}y$ has order $p$.
(Note that this result is false for $p=2$ and the quaternion group $Q_8$ is a counterexample.)