How does the Mac choose which connection to use when both Wifi and Ethernet are connected? When I'm connected to two networks with separate routers using Wifi and Ethernet, how does my Mac know what connection to use when I visit a website?
From the Apple Support database article regarding network connection priority:


  If you connect to the Internet or a network in several different ways
  (using Wi-Fi or Ethernet, for example), you can change the order of
  the network port configurations your computer tries when connecting to
  the Internet or network.
  
  If there are multiple active network port configurations when you try
  to connect, OS X tries the one at the top of the list first, and then
  tries the other port configurations in descending order.


In that support article it is also described how you can change the priority order of network connections in System Preferences.