Forum Discussion

cjackson1's avatar
cjackson1
New Contributor
2 years ago

Can I navigate to a webpage using custom HTTP headers

Hello

I have some keyword tests that have started failing since we added reCAPTCHA v3 (invisible reCaptcha thas works with a score instead of a challenge) to our page.

My Dev team do not want to disable reCAPTCHA in our non production environments and have asked me the following question;

 

"When a "device" requests a web page (where a device may be a browser, or Postman, or TestComplete), the request will include a handful of HTTP headers

Can TestComplete "read" a value from a URL, and then "write" that value into an HTTP header?  So, to be clear, not writing the value into a textbox on a web page, but instead writing the value into the HTTP headers used when fetching that web page."

 

Does anyone know if this is possible, or have done it themselves?

 

Thanks

Connie

6 Replies

    • cjackson1's avatar
      cjackson1
      New Contributor

      Thanks for the link. What we want to do is navigate to a web page, for example, our online payment form with a custom HTTP Header that will allow TestComplete to bypass the reCaptcha on the form.

       

      I can see after reading the article how to set headers using a script, but I still don't understand how to navigate to our online payment form with the custom header using a browser. Can I do that in TestComplete?   

      • krisstoffm's avatar
        krisstoffm
        Senior Member

        Hi

        This is an old post but i'm interressed in knowing if you had find a solution.

        I have the same need.

         

        Thanks

        KM

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I've only used this once to pass an authorisation token, which allows me to log into the system using my encrypted credentials. I had to get help from my development team, to construct this, and to understand how our web authentication works.

  • KB1's avatar
    KB1
    Champion Level 2

     

    TestComplete can read a value from a URL and write it into an HTTP header when requesting a web page. You can use the "WebUtil" object in TestComplete to send HTTP requests and modify the headers.

     

    Here is an example of how you can read a value from a URL and write it into an HTTP header using TestComplete:

    1. First, you need to get the value from the URL. You can use the "UrlParser" object in TestComplete to parse the URL and extract the value you need. For example:

     

     

     

    var value = UrlParser.GetUrlParameter("key");

    This will extract the value of the "key" parameter from the URL and store it in the "value" variable.

    1. Next, you can use the "WebUtil" object to send an HTTP request and modify the headers. You can use the "WebUtil.AddHeader" method to add a header to the request. For example:

     

     

     

    WebUtil.AddHeader("X-Custom-Header", value);

    This will add an HTTP header called "X-Custom-Header" to the request and set its value to the "value" variable that you extracted from the URL earlier.

    1. Finally, you can use the "WebUtil.Navigate" method to send the request and navigate to the desired web page. For example:

     

     
    WebUtil.Navigate("http://example.com");

    This will send an HTTP request to the specified URL with the "X-Custom-Header" header set to the value extracted from the URL.

     

    I hope this is what you were searching for