Use Selenium to close the Flipkart tab, open a pop-up window, and navigate back to the

WebDriver driver = new FirefoxDriver();
driver.get("https://www.flipkart.com");
driver.manage().window().maximize();
String parentWindowHandler = driver.getWindowHandle(); // Saving the parent window
String subWindowHandler = null;
Set<String> handles = driver.getWindowHandles(); // Getting all window handles
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()){
    subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler);

I attempted to switch back to the main window as well. Could anyone provide helpful suggestions or code for closing the pop-up?

Answer №1

If you're looking to use the java Robot API, you can utilize the java.awt.Robot libraries. A helpful example can be found here.

An interesting tip is that you can simulate pressing the Esc key with this API. This can be handy on websites like flipkart where pressing Esc helps get rid of annoying pop-ups.

Answer №2

When browsing Flipkart's website, you may come across a simple HTML modal pop-up. In order to access a new pop-up window, the window handle feature is utilized.

To close the pop-up, simply click on the cross located in the top right corner of the pop-up. It is important to implement waits using Selenium to ensure that the WebElement is found successfully.

Here is a helpful code snippet:

driver.get("https://www.flipkart.com");
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement cross = wait.until(
    ExpectedConditions.visibilityOfElementLocated(By.className("close-icon")));
cross.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

Utilizing the Java scanner to transfer variables between methods

I am currently working on developing a text-based calculator. This project involves a main class and a calc class, where all the calculations will take place and be called from the main class. However, I am encountering an issue with several variables in m ...

Troubleshooting error messages in the console during conversion of image URL to Base64 in AngularJS

While attempting to convert an image URL to Base64 using the FromImageUrl method, I encountered an error in my console. Access to the image located at '' from the origin 'http://localhost:8383' has been blocked due to CORS policy ...

"Modifying the height of an SVG <g> element: A step-by

Is there a way to adjust the height of a g element? Trying to set the height using {params} but it's not responding I made some changes in the comments because the svg is quite large (Scene.js) {/* Transformation */} <g transform="trans ...

Increasing the identifier of duplicated input fields using jQuery

There is a specific section in my form that consists of a select box and three checkboxes, which needs to be duplicated on request. While I have successfully cloned the div and incremented its specific div, I am facing challenges in incrementing the checkb ...

Implementing Dynamic CSS Styles in AngularJS

Essentially, I am facing a challenge on my page where a control needs to toggle two different elements with two distinct CSS classes upon being clicked. While I have successfully managed to toggle one of the controls, the other remains unchanged. Here is ...

Transform the string into a file format, followed by encoding it into base64

Is there a way to take the string const content="<div>How do I <b>convert </b> this string to file?</div>"; and convert it into an HTML file, then ultimately encode it as a base64 string? The method Buffer.from(content).toString(&ap ...

The variable maintains the same value both inside and outside of the loop

I have a list of objects that provide information to a variable, which creates "markers": var markers = [ //testPOW { mesh: ["campDome","POW"], color: iconRed, location: {lat: 43.30985465943113, lng: 11.898409657895801}, visible: true, id: "TestPO ...

Getting an error message like "npm ERR! code ENOTFOUND" when trying to install Angular CLI using the command "

Currently, I am eager to learn Angular and have already installed Node version 18.13.0. However, when attempting to install Angular CLI using the command npm install -g @angular/cli, I encountered an issue: npm ERR! code ENOTFOUND' 'npm ERR! sys ...

There appears to be a syntax error in the Values section of the .env file when using nodejs

I have been working on implementing nodemailer for a contact form. After researching several resources, I came across the following code snippet in server.js: // require('dotenv').config(); require('dotenv').config({ path: require(&apos ...

Executing Selenium commands exclusively in the Chrome console

Is it possible to use Selenium commands in the Chrome console (developer console) for testing UI? For example, can we run/test xpath queries like $x("//input[@name='inputname']") to find elements based on specific attributes? By Selenium command ...

Enhancing User Experience with Image Layers and Interactive Selection through Javascript

Hey there! I'm working on creating a fabric and background gallery for Greek letter apparel in my college town. If you're not familiar with what I mean, take a look at this example of a fabric letter here. The idea is to have customizable foregro ...

Executing Node.js Function from an External File Dynamically

Is it possible to run a Node function from an external file that may be subject to change? main.js function read_external(){ var external = require('./external.js'); var result = external.result(); console.log(result); } setInterva ...

What could be causing the malfunction of the v-bind attribute?

I am in the process of developing a straight-forward To-Do List application with VueJS. <template> <div> <br/> <div id="centre"> <div id="myDIV" class="header"> <h2 style="margin:5px">M ...

What might be causing the 500 internal error in jquery.min?

Hello, I am encountering a 500 internal server error when I click this button that performs the following action: $(".btn-email").on('click', function() { swal('Waiting','Please wait, sending email now','info'); ...

selenium encountering difficulty locating button element

I'm currently attempting to use Selenium in C# to locate a button. <a id="1|0AqnCSdkjQ0|none" href="" target="_self" rel="nofollow" class="download_link 1">Download</a> I've already tried using the ID and class, but without success. ...

Is NodeJS primarily used as a socket library for network communication?

Here is a server program written in C language using socket functionality provided by libC # include <unistd.h> # include <sys/socket.h> # include <sys/types.h> # include <string.h> #include <netinet/in.h> main(){ int listfd ...

Use selenium to locate the positions of hotels on a map

I am facing an issue with extracting the hotel location from this link. The format of the element is displayed below: view image description here This is the code I have written: driver = webdriver.Chrome() driver.get('https://www.cvent.com/venues/e ...

Converting XML to JSON using UTF-8 Encoding

I am currently working with xml2js to convert an XML feed into JSON format. However, I'm facing an issue where certain characters like Æ, Ø & Å are displayed as expected in the XML but appear differently after parsing. After parsing, I receive ...

Navigating collisions in the ECS architecture: Best practices

I'm currently developing a game using typescript and the ECS design pattern. One of the challenges I'm facing is handling collisions between different entities within the game world. I have an entity called Player which comprises several componen ...

Effortlessly move and rearrange various rows within an HTML table by utilizing JQuery alongside the <thead> elements

My JsFiddle has two tables and I want to switch rows <tr> between them using Jquery. However, due to the presence of the <thead> tag, it is not functioning properly. I suspect that the issue lies with the items in the selector, but I am unsure ...