There isn't really an official way to monitor what a user is doing in Selenium. The only thing you can really do is start the driver, then run a loop that is constantly checking the driver.current_url. However, I don't know what the best way to exit this loop is since i don't know what your usage is. Maybe try something like:
from selenium import webdriver
urls = []
driver = webdriver.Firefox()
current = 'http://www.google.com'
driver.get('http://www.google.com')
while True:
if driver.current_url != current:
current = driver.current_url
# if you want to capture every URL, including duplicates:
urls.append(current)
# or if you only want to capture unique URLs:
if current not in urls:
urls.append(current)
If you don't have any idea on how to end this loop, i'd suggest either the user navigating to a url that will break the loop, such as http://www.endseleniumcheck.com and add it into the code as such:
from selenium import webdriver
urls = []
driver = webdriver.Firefox()
current = 'http://www.google.com'
driver.get('http://www.google.com')
while True:
if driver.current_url == 'http://www.endseleniumcheck.com':
break
if driver.current_url != current:
current = driver.current_url
# if you want to capture every URL, including duplicates:
urls.append(current)
# or if you only want to capture unique URLs:
if current not in urls:
urls.append(current)
Or, if you want to get crafty, you can terminate the loop when the user exit's the browser. You can do this by monitoring the Process ID with the psutil library (pip install psutil):
from selenium import webdriver
import psutil
urls = []
driver = webdriver.Firefox()
pid = driver.binary.process.pid
current = 'http://www.google.com'
driver.get('http://www.google.com')
while True:
if pid not in psutil.pids():
break
if driver.current_url != current:
current = driver.current_url
# if you want to capture every URL, including duplicates:
urls.append(current)
# or if you only want to capture unique URLs:
if current not in urls:
urls.append(current)