WebDriver encounters difficulty clicking on a certificate error popup window

Currently, I am using webdriver 2.40.0 in C# to interact with my company's website. The issue arises when I encounter a certificate error page while trying to access certain elements. Specifically, after clicking the override link and entering some information, a pop-up window appears with another certificate error page. However, when I attempt to select this pop-up window, a "noSuchWindowException" is thrown. Here is a snippet of the code:

namespace webDriverDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            string setURL = "xxxxx";

            IWebDriver driver = new InternetExplorerDriver(@"C:\Drivers");
            driver.Url = setURL;
            String loginPage = driver.CurrentWindowHandle;

            var securityLine = driver.FindElement(By.Id("overridelink"));
            if (!securityLine.Equals(null))
            {
                securityLine.Click();
            }

            var enterBtn = driver.FindElement(By.Id("EnterButton"));
            enterBtn.Click();

            //Select the pop up window

            driver.Navigate().GoToUrl("javascript:document.getElementById('overridelink').click()");

            driver.SwitchTo().Window("xxxx");

I have attempted various solutions such as using

driver.Navigate().GoToUrl("javascript:document.getElementById('overridelink').click()")
, storing the current window handle in
riskPage = driver.CurrentWindowHandle;
, and attempting to switch windows with driver.SwitchTo().Window();. Unfortunately, it seems that identifying the window name of the certificate error page is posing a challenge and preventing me from accessing and interacting with its elements. Any assistance on resolving this issue would be greatly appreciated!

Answer №1

After triggering the event enterBtn.Click(); that causes the popup window to appear, it is necessary to change focus to the new window (using its window handle, not the title) in order to interact with it.

The handle for the popup window can be obtained from the driver.WindowHandles list.

var riskPageHandle = driver.WindowHandles.FirstOrDefault(hwnd => hwnd != loginPageWindowHandle);

if(riskPageHandle == null)
{
   //handle popup not found, either log an error or handle the situation accordingly
}
else
{
   //switch to the popup window
   driver.SwitchTo().Window(riskPageHandle);
   Console.WriteLine("Title of the Popup window: " + driver.Title);

   //proceed with accepting the certificate error (specific code required)
   driver.Navigate().GoToUrl("javascript:document.getElementById('overridelink').click()");
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why isn't my custom HTML attribute displaying correctly?

In my current React app project, I have been incorporating custom attributes to HTML tags and React components for End-to-End (E2E) tests using Testcafe. However, I am facing an issue where the additional data-test="burger-menu-btn" attribute is ...

Translate CSS into JavaScript while maintaining selector understanding

I am interested in developing a tool that can read a .css file and generate a function that will accept an array of class names as input and output the corresponding styles for an element with those classes, represented as a JavaScript object. This tool wo ...

Passing data from a method callback to a function and returning a variable in the same function

Is there a way to properly return the latlon variable from the codeAddress function? The typical 'return latlon' doesn't seem to work, possibly due to scope issues. Any suggestions on how to resolve this? function codeAddress(addr) { ...

Creating separate chunks for individual files in Vue CLI3JsonPropertyTitleFileType

I am working on a project using vue-cli3 and need to separate out a specific file for chunking due to IIS requirements. Currently, webpack chunks files based on default settings and also automatically creates chunks from dynamic imports in vue-router. How ...

Navigating Chrome and chromedriver directories within Jupyter Notebook with Selenium

Scraping a website with a Python notebook using Jupyter has been quite the challenge due to issues with Chrome and chromedriver location. The struggle is real, especially when working on a Linux WSL in a Windows PC. Despite trying various codes, even Selen ...

Ways to standardize the input email address?

While using express-validator, I came across an issue where I used normalize email for validation of email during sign up and stored the normalized email on the server. Validation code: router.post( "/signup", [ check("name").n ...

Selenium facing issues with detecting a second window in Internet Explorer

When my application triggers a new window on button click, I encounter issues with the response of the getWindowHandles() method in selenium webdriver. It only returns one window id, especially when there is a delay in calling the getWindowHandles(). This ...

Is there a way to transform the SmartyStreets' jQuery.LiveAddress plugin into its JavaScript SDK?

My website currently utilizes the jQuery.LiveAddress plugin, however, it was deprecated and subsequently removed by SmartyStreets back in 2014. <script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <s ...

Utilizing a specialized xyz tileLayer to specifically highlight a designated area on the map

I am looking to add the xyz tile layer from this link onto a leaflet map: http://weatheroo.net/radar/data/2019/07/15/18/40/{z}/{x}/{y}.png This particular weather radar composite is focused on Germany, hence why it only covers middle Europe. The specifie ...

Executing a component's function from a JavaScript file

Is it possible in React to call a function or method of a component from a separate JS file in order to modify the component's state? Here are three example files: First, App.js import React,{Component} from 'react'; import Login from &ap ...

An expected expression was encountered near the if condition

I am encountering an expression expected error in Visual Studio near if(isNullOr ........ if (value) { if (isNullOrUndefined(x.value) && isNullOrUndefined(x.value2)) { x.minMark + '-' + a + '*' + x.b + ' ' + ...

How can I ensure that I only include a field in a JavaScript object if the value is not null?

In my current setup, I am utilizing mongoose to write data to a MongoDB collection while ensuring there are no null fields. Default values have been set in the document for this purpose. During an update function call, certain fields may be null but I do n ...

validation using ajax and php

One question I have is, when I include document.getElementById('myPassword').value); in the validarDados function, it corresponds to valor. Then I need another variable, but valor1 isn't working as expected. The result of echoing $valor1; is ...

Can you explain the significance of syntax in sample code (typescript, react)?

const sampleFunction: (inputString: string) => string = inputString => { return inputString.split(""); } I'm a bit confused about the code below and would appreciate some clarification. I understand that only "string" as a type is accepted, b ...

Harmonizing Express (Passport) with AngularJS Routing

I have been working on developing a MEAN-stack application and I have reached the point of setting up user authentication. Following this tutorial: After implementing it into my project, I noticed that it works partially. The issue is that I can only acce ...

Exploring the movement from one component to another in React Native

When working with React Native, I encountered a challenge in navigating between two views. The issue arises from having the button to navigate on one component while my main component is elsewhere. I am using react-navigation for this purpose. Here's ...

Vite deciding to generate its own node_modules directory within the workspace rather than depending on a monorepo

I have organized a monorepo for a fullstack webapp with the directory structure outlined below: . ├── client │ ├── index.html │ ├── package.json │ ├── src │ └── vite.config.ts ├── node_modules ├── p ...

Information regarding gender vanishes upon refreshing the page

When the page is refreshed, the variable called jso disappears. Is there an alternative method for storing information that does not involve using a button? The goal is to have it work seamlessly when the page is reloaded without requiring any user action. ...

When utilizing $resource, Protractor experiences a timeout while trying to synchronize with the page

Currently, I am testing Protractor with a small AngularJS application. Here is the test scenario: describe('Testing Protractor', function() { var draftList; it('should count the number of drafts', function() { browser.get(&ap ...

Struggling to generate an HTML table using JSON data

Struggling with generating an HTML table from JSON data, I'm inexperienced and having trouble with the logic. The JSON data I have needs to populate a complex dynamic HTML table. The design of the table is intricate, making it challenging for me to i ...