Get Current URL

Get Current URL

How to Get the Current URL using Custom JavaScript

Have you ever needed to retrieve the current URL of a webpage for your automation tasks but found it challenging to do so? In this blog post, we will explore a method using custom JavaScript to easily capture the current URL without complicated processes.

Understanding the Process

In most scenarios, scraping the link or button that leads to the desired URL is a common approach. However, what if this method doesn't work for your specific scenario? If you find yourself in a situation where you need to scrape the current URL directly, adding a custom code step can be the best solution.

Implementing Custom JavaScript

To get the current URL using custom JavaScript, follow these steps:

  1. Click on the plus icon in your automation tool.
  1. Select the custom JavaScript option.
  1. Enter the following code: return window.location.href;

By including this simple line of code, you can effectively retrieve the current URL as if it were a scrape step. Let's walk through a quick demonstration to illustrate how this works in practice.

Testing the Automation

Running this automation will result in the current URL being captured in step two. When you proceed to paste or use the value from step two, it will reflect the URL since the custom JavaScript instructs it to do so.

Conclusion

In conclusion, utilizing custom JavaScript to fetch the current URL simplifies the process and makes it more efficient for your automation tasks. By integrating this method into your workflows, you can streamline the URL retrieval process and enhance the reliability of your automations.


Video


Steps

Step 1- Click on New automation—Click on Web

Notion image
 

Step 2-Click on Continue without cookies

Notion image
 

Step 3-Click on Custom Javascript

Notion image
 

Step 4-Enter your JavaScript—Click on Save

Notion image
 

Step 5- Click on Type

Notion image
 

Step 6-Write the element in the box —-Click on Confirm

Notion image

VIDEO TRANSCRIPT

So if we want to get the current URL, uh, in most scenarios we're gonna try to use scrape link to scrape like the button or whatever we click to get to that URL. But if that doesn't work in your scenario for whatever reason, and you are on A URL and you just need to scrape the current one. The best thing is gonna be adding a custom code step.

So we can click the plus icon and then custom JavaScript. And to get the current URL, we're gonna enter return window location. Do h ref, we can add a semicolon. We don't need to just, just add a semicolon. Um, so again, return and then a space window dot location. Do hre. And what this will do is this is gonna return this.

To this step as if this was a scrape step. So let me just record this really quick and demonstrate this. If we were to run this automation, it's going to get the current URL in step two. And then when we paste or type the value from step two, it'll be typing the value since that's what the custom JavaScript is telling it to return.

So we'll see that URL get pasted here.

Did this answer your question?
😞
😐
🤩