Forum Discussion

Anusha123451's avatar
Anusha123451
New Member
5 days ago

I'm not able to handle cookie pop up with test complete using java script,I'm using windows machine.

 

2 Replies

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Icon for Champion Level 3 rankChampion Level 3

    This depends on what kind of cookie popup you’re dealing with.

    If the cookie popup is part of the website (HTML-based banner), then TestComplete can handle it using JavaScript, because it’s part of the DOM. In that case, you should identify the Accept / Reject button using DOM methods (XPath, CSS selectors, text, etc.) and click it like any other web element.

    However, if the popup you’re seeing is a browser-level or OS-level dialog (for example Chrome/Edge privacy dialogs or Windows permission popups), TestComplete cannot reliably interact with it. These dialogs are not part of the web page DOM, so JavaScript, XPath, and Web Testing objects will not work on them.

    Recommended approaches on Windows:

    1. Disable the popup via browser settings (best practice)
      Launch the browser with arguments to suppress cookie and permission dialogs:
    Browsers.Item(btChrome).Run("--disable-notifications --disable-geolocation");
    1. Pre-set the consent cookie
      If the application allows it, set the cookie before loading the page:
    page.contentDocument.cookie = "cookie_consent=true; path=/;";

    This prevents the popup from appearing at all and is the most stable solution.

    1. Keyboard workaround (limited)
      For some browser dialogs, sending keys like [Enter] may work:
    Sys.Desktop.Keys("[Enter]");

    This is not reliable and depends on focus and browser behavior.

    🤖 AI-assisted response
    👍 Found it helpful? Click Like
    ✅ Issue resolved? Click Mark as Solution