0

I need to get the http request URL when a button is clicked in a webpage programatically. I am using selenium to trace the button and I am performing click on the button. on click of the button it makes a http request and the same can be traced in the network tab of the browser.

How can i get the request URL programatically once I trigger the button click using selenium.

Any other tools or libraries that I can use to achieve the same functions is also ok for me. I just need to be able to get the URL after button click programatically. This is a dynamic URL which changes periodically and the objective is to automate the download process through code.

Thanks in advance for any help!

1 Answers1

0

You can use JavaScript executor to get network data. Please refer https://stackoverflow.com/a/45859018/5966329 get request/response data from there.

DesiredCapabilities d = DesiredCapabilities.chrome();    
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
d.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
WebDriver driver = new ChromeDriver(d);
driver.get("https://www.google.co.in/");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
LogEntries les = driver.manage().logs().get(LogType.PERFORMANCE);
for (LogEntry le : les) {
  System.out.println(le.getMessage());
}

Python Equivalent:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import 
DesiredCapabilities

caps = DesiredCapabilities.CHROME

caps['goog:loggingPrefs'] = {'performance': 'ALL'}
driver = webdriver.Chrome(desired_capabilities=caps)

driver.get('https://stackoverflow.com')
for entry in driver.get_log('performance'):
    print(entry)

Please refer thread for more info python