I am trying to find the solution for the equation $ax=b$ where $a,b \in G$ and $G$ is a group with respect to the operation, multiplication. This is what I gathered from different books $$ax=b$$ pre multiply both sides with $a^{-1}$. $$(a^{-1})ax=(a^{-1})b$$ Then it says according to associative property $aa^{-1}=e$. $$ex=(a^{-1})b$$ $$x=(a^{-1})b.$$ But the thing that I don't understand is the step where the associative property is applied above because according to associative property(w.r.t multiplication)
$$ \forall a,b,c \in G , a(bc)=(ab)c$$ and in this case we know that $a$ and $a^{-1}$ belongs to $G$ but $x$ does not. So how can one apply associative property in such a situation. Please elucidate. Thanks in advance.
I think your confusion about whether $x$ lies in the group was addressed in the comments.
The associativity step that you're looking for comes right after you left-multiply by $a^{-1}$ to get $$(a^{-1})(ax) = a^{-1}b.$$ On the left you need to apply associativity to see that: $$a^{-1}(ax) = (a^{-1} a)x = ex.$$
Hope this helps!