Selenium - Find out where script was downloaded fromAsk Question


I have to validate that a web application, when executed in the client browser, is fetching some assets (*.js) from a particular remote server.

Say two options exist: whether it gets the script from server A or it gets a copy from server B. I need to assert (based on some preconditions) that the script was downloaded from server A.

The question: Is there a way to inspect source url of loaded javascript using selenium (preferably with python)?


Here it is a possible solution to extract url of javascript libraries from the stackoverflow site.

You should adapt the solution to the site you are working on.

driver = webdriver.Firefox()
link= driver.find_elements_by_tag_name('script')
for i in link:
    print i.get_attribute("src")

Example of output:

There are various strategies to locate elements in a page. You can use the most appropriate one for your case (

标签: selenium
© 2014 TuiCode, Inc.