Forum Discussion

bb1832j's avatar
bb1832j
Occasional Contributor
7 years ago

When verifing links with hash (#) in url, XmlHttpRequest object always returns 400 BAD REQUEST

Hello,
I am trying to verify the links on a web page using the XmlHttpRequest object.  When I check a url that
has the hash (#) symbol in the address I always get a "400 BAD REQUEST" status, even for links I know
are valid.  Is there a way to work around this issue?

Thanks.

11 Replies

  • cunderw's avatar
    cunderw
    Community Hero

    A 400 means that the request was malformed. In other words, the data stream sent by the client to the server didn't follow the rules.

     

    # in a url is called an anchor link, and it's how your browser knows where in the page to position you. It is not a correct endpoint to send a request to. So in a nut shell you're trying to send a request to something that doesn't actually exist. 

     

    Use you're browsers dev tools to watch the network requests when you click one of the links. It will striped out the anchor tags.

     

    The only work around would be to removing anything after the #, but more than likely you would just be sending the same request over and over at that point. 

     

    What is your end goal here? If you're wanting to test APIs and end points then you should look at something like ReadyAPI. 

     

    If you actually want to verify the UI and clicking links takes you to the correct place, then XmlHttpRequest isn't the approach I would use. I would actually click the link and validate the correct page / position loads.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Oh, crud... you know, LinoTadros demonstrated a way of using an Attributes checkpoint to do this kind of thing without actually doing any navigation.  I'll need to go back and check my notes from Connect 2017 but it was a pretty cool way of validating links on a page. Anyone else remember that? Marsha_R?

      • cunderw's avatar
        cunderw
        Community Hero

        I think the example LinoTadros was using may have just been verifying that all the links are present using NativeWebObject's find method to find everything that was a link. If I'm understanding correctly bb1832j wants to verify the link has a successful response. 

  • bb1832j's avatar
    bb1832j
    Occasional Contributor

    I did try to use the WebTesting.WebAccessibility.Check() method.  The page I tested had several links intentionally broken.  The method still returned all links as passed.  With the XmlHttpRequest object, I am able to see the status message and that the broken links were found.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Please show your full code.  I'm curious as to why it failed to find the broken links.

  • bb1832j's avatar
    bb1832j
    Occasional Contributor

    For the Web Accessibility object?  There is not a lot of code...

    function WebAccessibilityCompare()
    {
      var WebObject;

     

      // Obtains the WebAccessibility object
    //  WebObject = WebTesting.WebAccessibility1;
    //  WebObject = WebTesting.WebAccessibility2;
    //  WebObject = WebTesting.WebAccessibility3;
      WebObject = WebTesting.WebAccessibility4;
      // Checks the web page
      // If the verification fails, posts a warning message to the test log
    //  WebObject.Compare(Page, true, 1000, lmWarning);
    //WebTesting.WebAccessibility1.Check();
    //WebTesting.WebAccessibility2.Check();
    //WebTesting.WebAccessibility3.Check();
    WebTesting.WebAccessibility4.Check();

    }