I'm using 4.2 and x-ray mode isn't working properly

Welcome :tada:…

that’s for spam-preventions… you only have to spend some more minutes in the forum and look at some other post (maybe even search for a similar ; top right; :mag: --icon ) for doing so… (see FAQ: Why only one image?)

Anyway: usually if you click on any objects which does have one behind it (if Xray or not) another click will select “the other one”. (This may have changed in 4.2 ??) So blender selects the one most in front first.