How to replace remote resources with local resource in a page with Selenium?

0 votes

Is it possible to run an automatic test on a web page with Selenium and force it to replace the remote resource with another one in local?

Like replacing this:

<html>

  ...

  <script href="http://cnd.foo.bar/lib.js"/>

  ...

</html>

with

<html>

   ...

   <script href="http://localhost:3000/lib.js"/>

   ...

</html>

Aug 8, 2018 in Selenium by Martin
• 4,210 points
13 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

You could change URL for that script with a command:

<tr>

    <td>runScript</td>

    <td>document.querySelector('script[src=&quot;http://cnd.foo.bar/lib.js&quot;]').setAttribute('src', 'http://localhost:3000/lib.js')</td>

    <td></td>

</tr>

But when you execute your Selenium script browser is allready downloaded CDN javascript and nothing will happen.

You could delete reference to CDN js add reference to local javascript to your DOM :

<tr>

    <td>runScript</td>

    <td>var sc = document.querySelector('script[src=&quot;http://cnd.foo.bar/lib.js&quot;]');sc.parentNode.removeChild(sc);</td>

    <td></td>

</tr>

<tr>

    <td>runScript</td>

    <td>var js = document.createElement('script'); js.src = 'http://localhost:3000/lib.js'; document.head.appendChild(js);</td>

    <td></td>

</tr>

That will load new javascript. But maybe some scripts from CDN will be executed on page load.

IMO best solution is run localhost on port 80 and then set CDN url to 127.0.0.1 in hosts file.

answered Aug 8, 2018 by Samarpit
• 5,130 points

Related Questions In Selenium

0 votes
1 answer

How to create a test case with TestNG in Selenium?

Hey Deepak, to create a Test Case ...READ MORE

answered 10 hours ago in Selenium by Abha
• 5,760 points
6 views
0 votes
1 answer
0 votes
1 answer

How to scroll the Page up or down in Selenium WebDriver? (using java)

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,030 points
4,343 views
0 votes
1 answer

How to upload a resume to a website using selenium in python?

Use this code, this will help you: from ...READ MORE

answered Apr 20, 2018 in Selenium by Vardy
• 2,280 points
986 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
59 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
424 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
44 views
0 votes
1 answer

How to open a browser window in full screen using Selenium WebDriver with C#

Simply Use this: driver.Manage().Window.Maximize(); READ MORE

answered Jun 7, 2018 in Selenium by Samarpit
• 5,130 points
1,844 views
0 votes
1 answer

How to login a forum using Selenium with Python

You should try to directly log in ...READ MORE

answered Apr 27, 2018 in Selenium by Samarpit
• 5,130 points
151 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.