Magnetic force on an electromagnet I am confused of how electromagnets are claimed to behave like permanent magnets due to their similar magnetic fields. For example, if we place a solenoid with current passing through inside a uniform magnetic field (between large magnetic plates), such that it aligns with the magnetic field generated by the solenoid as shown:

(Purple arrows represents the magnetic field while yellow represents current)
Inspecting the magnetic field on the wire, since there are theoretically no magnetic field on the line of wire created by the solenoid itself, the resultant magnetic field on the wire would be the uniform magnetic field, which is pointing to the left. We can then find the direction of the Lorentz force acting on the wire:

Despite of my messy drawing, we can see that the magnetic force acting on the solenoid just simply stretches it outwards! So for what reason does it still behave like a normal magnet, which would get pulled along the uniform magnetic field?
 A: It can be shown that the magnetic field due to a solenoid (inside the solenoid close to its axis), is $$B = \mu_0 n i$$ where $$n=\frac{N}{L}$$ is the number of turns per unit length.
We can also calculate that the magnetic field outside a solenoid is $$B\approx 0$$
But we can also make this argument by a qualitative analysis, instead of long calculations that you may be able to find in a standard undergrad text book on electromagnetism.
Inside the solenoid the magnetic flux will be high since we have a large number of magnetic lines of force that are passing through the cross-sectional area of the solenoid.  However, outside the solenoid, the density of field lines per unit area decreases quickly. That is, the number of lines of force per unit area becomes significantly small the further away from the axis you go. In comparison to inside the solenoid, the magnetic field outside is affectively zero.
So the net magnetic field of a solenoid resembles a permanent magnet.
A: Just adding to Joseph H's answer.
Neither a permanent magnet nor an electromagnet are drawn along a uniform magnetic field. Rather, all magnetic dipoles are drawn along the gradient of the magnetic field, $\nabla |B|$, whether they arise from macroscopic current loops (an electromagnet) or the gestalt of countless atomic current loops (a permanent magnet).
We can approximate a permanent magnet as a single macroscopic magnetic dipole with $q_{m_{north}}= A$ on the north pole and $q_{m_{south}} = - A$ on the south pole, separated by a distance vector $\vec L$ from south to north, with both the north and south poles approximated as points.
In a uniform magnetic field, because $\vec F=q_m \vec B$, a dipole thus experiences net force $\vec F_{net} = (A-A)\vec B = 0$ and net torque $A{\vec L} \times {\vec B}$.
That is to say: in a uniform magnetic field, the magnet will experience torque which will cause it to oscillate about its axis like a pendulum in a gravitational field if its initial condition is displaced from equilibrium, but will experience no net force.
What about a non-uniform field? Then for a sufficiently large |L|, we would need to separately calculate the magnetic force at both ends and add: $\vec F_{net} = A(\vec B_{north} - \vec B_{south})$. For large L and any possible initial orientation of the poles and magnetic field, this would get us a fairly gnarly system of differential equations. But for L small enough that the magnetic field at both ends is pointed in the same direction, and an initial orientation of the dipole in the same direction as the magnetic field, this is just $A \nabla |B|$.
