A.K.K
A.K.K

Reputation: 93

How to parse a URL from string in selenium IDE

which results as

MyCode = "<iframe src="http://myportal.com/mysales/Agent/index/4eb29642ce24e8.22143850/embedded" height="650" width="605" frameBorder="0"></iframe>"

I need to have only the URL part in another variable from the string above "http://myportal.com/mysales/Agent/index/4eb29642ce24e8.22334455/embedded" in order to proceed with the remaining test case. Thanks in advance.

Upvotes: 2

Views: 1471

Answers (2)

Lee Kowalkowski
Lee Kowalkowski

Reputation: 11751

Something like:

<tr>
    <td>storeEval</td>
    <td>'${MyCode}'.replace(/.*src="(.*?)".*/, $1)</td>
    <td>url</td>
</tr>

This will use JavaScript to set a variable called url to the value of the src attribute within your MyCode variable.

Upvotes: 1

chim
chim

Reputation: 8573

The first command below stores the href attribute of any element, you can modify it to your needs.

The third command uses javascript to get the pathname attribute of the DOM object.

Hope this answers your question.

If you open the IDE click on the source tab in the main window and copy and paste the code below between the tags, you'll be able to run the test on this page, or any other stack overflow page.

<tr>
    <td>storeAttribute</td>
    <td>css=.profile-link@href</td>
    <td>href</td>
</tr>
<tr>
    <td>echo</td>
    <td>${href}</td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>this.browserbot.getUserWindow().document.getElementsByClassName('profile-link')[0].pathname</td>
    <td>pathname</td>
</tr>
<tr>
    <td>echo</td>
    <td>${pathname}</td>
    <td></td>
</tr>

Upvotes: 1

Related Questions