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

Retrieve data from two separate files and store it as a two-dimensional array in JavaScript

Is there a way to read and convert two .txt files into a 2d array? I currently have a code snippet that looks like this : var fs = require('fs') file = './text1.txt' fs.readFile(file,'utf-8', (e,d) => { textByLine = d.s ...

Dealing with unexpected events in WebDriver/Selenium

Can Selenium be configured to pause and wait for user input in the event of unexpected occurrences, such as a message box, new window, warning, alert, or any other interruptions? For instance, if new functionality is introduced into the code and the Sele ...

Assigning specific class names to elements within an array using JavaScript

Currently, I'm attempting to assign a unique className to option elements within a select element by utilizing a conditional if statement. The goal is to apply one class name to the first half of the array and a different class name to the second half ...

populate the empty slots in an array with the correct numbers

Having two pre-sorted arrays as shown below: [1,2,4,5,8] [x,x,x,x,x] The goal is to fill in the missing elements with 'y' in the corresponding array, resulting in: [1,2,3,4,5,6,7,8] [x,x,y,x,x,y,y,x] Although the data arrives separately, they ...

Experiencing excessive CPU usage while utilizing a progress bar in Angular

Whenever I try to load a page with 2 progress bars, my CPU usage goes through the roof... I decided to investigate and found that once I removed them, the site's speed improved significantly. Here's a code snippet of one of the progress bars: ...

What is the best way to dynamically change the JSON-LD Script for the Schema?

Below is the script in question. Please read through it carefully. <script type="application/ld+json"> { "@context": "http://schema.org/", "@type": "Product", "name": "Bat, &q ...

Prefering `window.jQuery` over the yarn version

I am currently in the process of transitioning to Vite 3 with Vite Ruby on Rails from Webpacker and Webpack. One major issue I have encountered is that my system functions as a CMS. Some of our long-standing clients have jQuery code embedded directly withi ...

Compare the selected values of radio buttons with an array and find matches

I have multiple radio button groups, where each selection in a group corresponds to predefined values in an array. For example, selecting option 1 in Group 1 will increment values A and B by 1, while selecting option 2 will increment B, C, and D. The goal ...

Basic Search tool, displaying a <div>

Hey there, I've been searching for a solution for a while now and haven't found one yet. So here's my question: I created a simple website to display random recipes for those times when you're not sure what to make for dinner. I also w ...

Does calling XmlSuite.SetFileName(XXX) result in the creation of a real file?

Is it possible to convert a virtually created XML file into a physically one? For example, let's say I am generating the testng.xml file programmatically and then running my test scripts accordingly. I have attempted the following code but it seems t ...

Personalized authentication in asp.net web api

I am working on a project that involves both Web Api and MVC. The authentication process is managed by FormsAuthentication, which generates a cookie containing user-specific data. To ensure restricted access, I have enhanced System.Web.Mvc.AuthorizeAttrib ...

How come the "colspan" attribute is not functioning properly in my table?

Check out the simple table form I created on jsfiddle. Here is the code snippet: <table> <tr> <td class="field_label">name</td> <td>*</td> <td> <input type="text"> ...

What is the best way to store and retrieve all the variable data from a .js file on a user's device?

I'm looking for a way to save and load multiple variables in JavaScript that determine a "save" state. These variables are stored in a file named "variables.js." Is there a simple method to easily save all the information in this file and then load i ...

Javascript eval function providing inaccurate results

I have encountered a problem while using eval() for a calculator I am developing. When I input the following code: console.log(eval("5.2-5")); The output is: 0.20000000000000018 I am confused as to why this is happening. Thank you for your assistance. ...

The input value is displaying one value, but the output is showing a different value

I am encountering a unique issue and could really use some assistance. <input class="testVal" type="number" id="GT_FIRING_TEMPERATURE" value="-17" name="degC" onchange="angular.element(this).scope().unitConversion(value,name, id)"> Despite the valu ...

How can I filter rows in HTML using Vue.js based on string options?

When selecting different options, I want to dynamically add new rows. For instance, if "kfc" is selected, a specific row should be added. If "cemrt" is chosen, another row needs to be included. <div class="card-content" v-for="(bok, index) in rules" :k ...

Ionic - numerical age selector control

Currently working on a hybrid mobile app and ran into a specific issue. I'm in the process of adding new items to my left side menu, including an age number spinner component (min:18, max:65). After searching through various sources and Ionic documen ...

What is the method for transmitting a message from localhost to a React frontend?

I am currently running a WebSocket server that is receiving streams of messages from an MQTT source. These messages are then sent to a localhost server on port 8080. The messages being received are actually a stream of random numbers. Below is the Python ...

Avoid activating automatic save feature in Material UI data grid

After creating a data-grid and attempting to add records, I encountered an issue where pressing the TAB key automatically saved the data when focusing on the save button without manually pressing enter. How can this behavior be prevented so that manual con ...

PHP query will execute even in the absence of clicking the button

I'm encountering an unusual issue. I've defined a query to insert two names into the database, and I've used Javascript(Jquery) to ensure it only runs when the create button is clicked. However, the script seems to be executing every time I ...