xdotool allows you to simulate keyboard input, control mouse actions, move or resize windows, and more. It achieves this by leveraging the X11 XTEST extension along with other Xlib functions.
# List all visible window IDs matching a given name
xdotool search --onlyvisible --name "127.0.0.1:3393"
52428807
100663984
# Get a specific window ID
xdotool search --name "127.0.0.1:3393" | awk 'NR==2'
100663839
xdotool windowactivate 100663839
xdotool windowactivate --sync 100663984 key Right
xdotool windowactivate --sync 100663984 type "Hello World"