I've recently had to investigate why the onboard WiFi connection on one of my Raspberry Pi V3 models wasn't working. I'm sure that this stopped working after an update but I cannot be certain. The following information only applies to the onboard WiFi on a Pi V3 - I don't need or require a separate USB WiFi dongle.
Troubleshooting turned out to be quite involved. I had tried to perform the usual commands of disabling and then re-enabling the WiFi interface (sudo ifdown wlan0 && sudo ifup wlan0) to no avail.
Reinstalled wpasupplicant package - still nothing. This action blatted my /etc/wpa_supplicant/wpa_supplicant.conf file so I recreated that from a working Raspberry Pi:
C3PI6:/run $ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
My system tray icon resolutely refused to play ball and was showing the dreaded 'No wireless interfaces found'. Working from a Korn shell, I went back to basics and monitored the syslog output to see if I could work out where it was going wrong. After issuing the interface down command (sudo ifdown wlan0) I could see that I was getting an error about the lockfile state, or rather the lack of one. I saw that the directory of /run/network wasn't present so I created that. I created the lockfile by using the 'touch' command to simply touch the file and therefore create it:
C3PI6:/home/pi $ sudo ifdown wlan0
ifdown: failed to open lockfile /run/network/.ifstate.lock: No such file or directory
C3PI6:/home/pi $ sudo touch /run/network/.ifstate.lock
touch: cannot touch ‘/run/network/.ifstate.lock’: No such file or directory
C3PI6:/home/pi $ cd /run
C3PI6:/run $ cd network
-ksh93: cd: network: [No such file or directory]
C3PI6:/run $ sudo mkdir network
C3PI6:/run $ sudo touch /run/network/.ifstate.lock
C3PI6:/run $ sudo ifdown wlan0
ifdown: interface wlan0 not configured
C3PI6:/run $ sudo ifup wlan0
May 24 11:48:43 C3PI6 kernel: [ 364.071977] brcmfmac: power management disabled
May 24 11:48:43 C3PI6 wpa_supplicant: Successfully initialized wpa_supplicant
May 24 11:48:44 C3PI6 wpa_supplicant: wlan0: CTRL-EVENT-REGDOM-CHANGE init=USER type=COUNTRY alpha2=GB
May 24 11:48:44 C3PI6 systemd: Reloading OpenBSD Secure Shell server.
May 24 11:48:44 C3PI6 systemd: Reloaded OpenBSD Secure Shell server.
May 24 11:48:44 C3PI6 wpa_supplicant: wlan0: Trying to associate with 00:24:a5:bc:2f:e5 (SSID='Johnnys_WIFI_working' freq=2447 MHz)
May 24 11:48:44 C3PI6 wpa_supplicant: wlan0: Associated with 00:24:a5:bc:2f:e5
May 24 11:48:44 C3PI6 wpa_supplicant: wlan0: WPA: Key negotiation completed with 00:24:a5:bc:2f:e5 [PTK=CCMP GTK=TKIP]
May 24 11:48:44 C3PI6 wpa_supplicant: wlan0: CTRL-EVENT-CONNECTED - Connection to 00:24:a5:bc:2f:e5 completed [id=0 id_str=]
May 24 11:48:44 C3PI6 dhcpcd: wlan0: carrier acquired
May 24 11:48:44 C3PI6 dhcpcd: wlan0: IAID eb:9b:ad:32
May 24 11:48:45 C3PI6 dhcpcd: wlan0: soliciting a DHCP lease
May 24 11:48:45 C3PI6 dhcpcd: wlan0: offered 192.168.1.106 from 192.168.1.1
May 24 11:48:45 C3PI6 dhcpcd: wlan0: soliciting an IPv6 router
May 24 11:48:50 C3PI6 dhcpcd: wlan0: leased 192.168.1.106 for 86400 seconds
May 24 11:48:50 C3PI6 avahi-daemon: Joining mDNS multicast group on interface wlan0.IPv4 with address 192.168.1.106.
May 24 11:48:50 C3PI6 avahi-daemon: New relevant interface wlan0.IPv4 for mDNS.
May 24 11:48:50 C3PI6 dhcpcd: wlan0: adding route to 192.168.1.0/24
May 24 11:48:50 C3PI6 avahi-daemon: Registering new address record for 192.168.1.106 on wlan0.IPv4.
May 24 11:48:50 C3PI6 dhcpcd: wlan0: adding default route via 192.168.1.1
May 24 11:48:52 C3PI6 ntpd: Listen normally on 4 wlan0 192.168.1.106 UDP 123
May 24 11:48:52 C3PI6 ntpd: peers refreshed
As you can see from the above, my WiFi is now working on IP 192.168.1.106 and I can therefore disconnect the Ethernet cable as this Pi runs headless and wireless.
Please note - check that you have the following packages installed, and if not, install them: wireless-regdb, crda, iw
The eagle-eyed amongst you will have noted that I have turned off power-management of the WiFi interface as this can cause problems/instability. I have included a copy of the file that is located at /etc/network/interfaces:
C3PI6:/var/log/apt $ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
iface lo inet loopback
iface eth0 inet manual
iface wlan0 inet manual
Note - the last line/entry shows the power management switched off.