Stop loop on URL change?

I currently have a script that reads a csv, opens the column, waits for the page to load, captures URL via store and saves it to a new CSV.

  1. How can I modify it so it writes the new URL on the same row as the URL it visits in the same CSV file?

  2. After awhile, the page URL catches the automation and creates a URL that contains “checkpoint” or “authwall” - how can I modify the script so that when it catches this it stops the loop and alerts the user? For the loop now I use the “Play loop…” feature instead of code. Thank you very much for your advice!

    {
    “Name”: “LinkedIn visit and capture URL”,
    “CreationDate”: “2021-3-1”,
    “Commands”: [
    {
    “Command”: “csvRead”,
    “Target”: “4861_LinkedIn_URLS.csv”,
    “Value”: “”
    },
    {
    “Command”: “open”,
    “Target”: “{!COL1}", "Value": "" }, { "Command": "waitForPageToLoad", "Target": "", "Value": "" }, { "Command": "store", "Target": "{!URL}”,
    “Value”: “!csvLine”
    },
    {
    “Command”: “csvSave”,
    “Target”: “links.csv”,
    “Value”: “”
    },
    {
    “Command”: “executeScript_Sandbox”,
    “Target”: “return 1000 + Math.floor(Math.random()*5000);”,
    “Value”: “waittime”
    },
    {
    “Command”: “pause”,
    “Target”: “${waittime}”,
    “Value”: “”
    }
    ]
    }

Simple solution

If with url condizion and gotolabel

When url change execute gotolabel and go exit from loop

1 Like

So to use this I can’t combine it with “Play loop…” feature I have to make my own loop correct?

What is the problem ?

In my opinion this is an easy work, read my post and you solve your problem

I would think you could still use the “Play loop…” feature, you would need an If statement, though. At the point where the decision is made, you would just have a “gotoIf_v2” and the label it goes to could max out your ${!LOOP} counter variable.

I create my own loops, so I’m not very familiar with the “Play loop…” feature. If there’s a way to code in an exit, that would be nice, otherwise just max that variable and you should be done.

1 Like

Hi newuserkantu - since I am new to this I asked a clarifying question on combining if, gotolabel and the “Play loop…” functionality. Thanks!

Hi Amanda! Great point.

I figured out a simple albeit inelegant solution without using IF. Since the problem is that basically my automation gets detected and I get bumped into a different page I added a verifyElementPresent condition, this way if the page that is loaded doesn’t have the name of a person it would throw an error. I went under settings -> Replay -> If error happens in loop -> selected “Stop”. This way when my script ends up visiting a page that the element is missing it will throw an error and stop the script.

1 Like