Both
去厕所 and
上厕所 are correct, but native speakers lean on
上厕所 for the 'act of using the toilet' and
去厕所 more for the directional 'walk over to the bathroom'.
我上完厕所就走 (after I use the toilet I'll go) vs
我去了一趟厕所 (I took a trip to the bathroom) — feel the difference.