# Open URL using variable or data file

**URL:** <https://forum.katalon.com/t/open-url-using-variable-or-data-file/46276>\
**Category:** Web Testing\
**Tags:** katalon-recorder\
**Created:** [August 7, 2020, 1:21pm UTC](https://forum.katalon.com/t/open-url-using-variable-or-data-file/46276 "2020-08-07T13:21:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iammund](https://avatars.discourse-cdn.com/v4/letter/i/9dc877/32.png) [@iammund](https://forum.katalon.com/u/iammund)\
**Post date:** [August 7, 2020, 1:21pm UTC](https://forum.katalon.com/t/open-url-using-variable-or-data-file/46276/1 "2020-08-07T13:21:49Z")

</div>

Hi, i’m getting how to get this work.

I’m trying to open URL from a source file or a variable. but i don’t know how it works.

here’s a screenshot of the result i’m getting:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/2/22d9eca52d56963047cbeaad480191b0bf594c77.png)  
 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/0/0e1b4901b683fdfee1cf417d0e97d2ea58c2a4d3.png)  
 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/f/f1c014cbf54bed36e0f9928a530f9959c1964047.png)

Thank you

---

<div class="post-metadata">

**Author:** ![iammund](https://avatars.discourse-cdn.com/v4/letter/i/9dc877/32.png) [@iammund](https://forum.katalon.com/u/iammund)\
**Post date:** [August 7, 2020, 1:38pm UTC](https://forum.katalon.com/t/open-url-using-variable-or-data-file/46276/2 "2020-08-07T13:38:06Z")

</div>

nevermind, i found a solution from this post

> [@How can I run my test case on URL#1, then on URL#2, then on URL#3, and so on](http://forum.katalon.com/t/how-can-i-run-my-test-case-on-url-1-then-on-url-2-then-on-url-3-and-so-on/45487):
>
> My data is in users.csv which has only one column: a list of URLs (URL#1, URL#2, URL#3, and so on.) URLForEachUser is the name of the one column in users.csv. As you probably surmised, I want to run my test case on URL#1, then on URL#2, then on URL#3, and so on. Test Case #1 fails completely Test Case #1 is… storeCsv | users.csv, 0, URLForEachUser URLForEachUser open | ${URLForEachUser} Test Case #2 does not work properly Test Case #2 opens URL#1, URL#2, URL#3 and so on from users.csv. Ho…

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/9/9074712043d58f14c5d1e5159aea0a9aa96adae7.png)

thanks

---

<div class="post-metadata">

**Author:** ![Lewis-H](https://avatars.discourse-cdn.com/v4/letter/l/49beb7/32.png) [@Lewis-H](https://forum.katalon.com/u/Lewis-H)\
**Post date:** [September 2, 2020, 2:40pm UTC](https://forum.katalon.com/t/open-url-using-variable-or-data-file/46276/3 "2020-09-02T14:40:27Z")

</div>

Old style string concatenation can be used

> > > id = “3333333”  
> > > url = “[https://example.com/%s](https://example.com/%25s)” % id  
> > > print url  
> > > [https://example.com/3333333](https://example.com/3333333)

The new style string formatting:

> > > url = “[https://example.com/{0}](https://example.com/%7B0%7D)”.format(id)  
> > > print url  
> > > [https://example.com/3333333](https://example.com/3333333)

The reading for file as mentioned by avasal with a small change:

f = open(‘file.txt’, ‘r’)  
for line in f.readlines():  
id = line.strip(‘\n’)  
url = “[https://example.com/{0}](https://example.com/%7B0%7D)”.format(id)  
urlobj = urllib.urlopen(url)  
try:  
json\_data = json.loads(urlobj)  
print json\_data  
except:  
print urlobj.readlines()
