Praise be to Allah.
If you cannot have children normally and you have turned to artificial fertilisation – whilst paying attention to the guidelines on that – in that case there is nothing wrong with trying to decide the gender of the foetus, because of the permissibility of artificial fertilisation in your case. See the answer to question no. 98604.
But if you are able to have children in the normal manner, it is not permissible for you to resort to artificial fertilisation with the aim of choosing the gender of the foetus, except in cases of necessity having to do with hereditary diseases that affect only females and not males, as stated in the resolution of the Islamic Fiqh Council. However, it is permissible to follow natural methods of choosing the gender, such as following a particular diet, chemical washes and choosing the time of intercourse according to the time of ovulation, because these are permissible means and there are no reservations concerning them.
See also the answer to question no. 135487
And Allah knows best.