Interacting with CSS buttons using Selenium

Currently, I am working on a test case in Java where I am using Selenium to record a series of events and then play them back on an application. Here is the code snippet I have:

// *The app opens a new window*
// Get handle of the main window
        String mainWindowHnd = webDriver.getWindowHandle();
        // Get all open window handlers
        Set openWindows = webDriver.getWindowHandles();

    Iterator ite=openWindows.iterator();
    // Select the new windows (there are two that are open)
    while(ite.hasNext())
    {
        String popupHandle=ite.next().toString();
        if(!popupHandle.contains(mainWindowHnd))
        {
            webDriver.switchTo().window(popupHandle);
        }
    }

    WebElement liveId = webDriver.findElement(By.id("c_clogoc"));

The ID of the last statement is correct but inaccessible due to a CSS banner that appears when the new window opens. When running Selenium IDE, these are the recorded events:

Command :: Target

click css=a.close

I am wondering how I can replay this command in Java so that the WebDriver closes the banner?

Answer №1

Utilize the findElement method with a CSS selector:

driver.findElement(By.cssSelector("a.close")).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

Website Responsiveness - inquiries for all needs

My first responsive website project has hit a roadblock, as I struggle to understand how to implement media queries effectively. Here's a snippet of my code... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/x ...

Exploring the various functions of Android ListView

Currently, I am populating a custom ListView with data from a JSON request and would like to add an OnItemClickListener. Here is how I have implemented it: ListView lv = (ListView) findViewById(R.id.MessageList); lv.setOnItemClickListener(new android. ...

How to overcome the need to click and hold using Python with Selenium

Attempting to scrape a website proves difficult due to a persistent "click & hold" captcha prompt that I am unable to bypass. The following arguments have been incorporated into my code: option.add_argument('--profile-directory=Default') option. ...

Java Regex: Understanding the Version Discrepancy

It appears that the regex escaping behaves differently across various Java versions. The compilation works perfectly fine in Java openjdk 16.0.1 However, Java openjdk 11.0.11 throws this compilation error: test.java:15: error: illegal escape charac ...

Is there a way to use jQuery to make a div fade in and toggle over another

I have created a test page and I am looking to achieve a specific effect when the page loads. I want everything on the page to be hidden initially. When I click on the "About" text, I want it to fade in using fadeToggle(); however, when I click on "My work ...

Automated Web Scraping with Selenium: Utilizing the Next Button

I am currently attempting to extract press releases from the Federal Reserve's official website at https://www.federalreserve.gov/newsevents/pressreleases.htm. In order to access documents from past years, I need to navigate to the next page by clicki ...

Is it possible for CSS to automatically style paragraphs based on the preceding heading class?

Looking to create some unique CSS rules for formatting interview transcripts. The format I have in mind is as follows: <h2 class="interviewer">Alice: [00:00:00]</h2> <p>Is it ok if I ask you a question now?</p> <h2 class="inter ...

JavaScript Processing Multiple Input Values to Produce an Output

Hello, I am working on creating a stamp script that will allow users to enter their name and address into three fields. Later, these fields will be displayed in the stamp edition. Currently, I have set up 3 input fields where users can input their data. He ...

How can you determine if a DIV element is within view in HTML (without being overflowed)?

Is there a way to determine if a DIV is within its container and therefore visible? In this scenario, the active button (highlighted) can be seen because it is contained within the boundaries: However, in this case: The active button cannot be viewed as ...

Refreshing frequency and reattempts when using selenium on a webpage

I am currently utilizing selenium with python to download a file from a URL. from selenium import webdriver profile = webdriver.FirefoxProfile() profile.set_preference('browser.download.folderList', 2) # custom location profile.set_preference(& ...

Designing stylesheets for larger screens to optimize the layout

I am currently working on the front-end design of a website and could use some assistance regarding element sizing. While the layout and elements look great on my 19-inch, 1440x900 resolution monitor, I noticed that everything appears tiny when viewed on a ...

Arrange list items dynamically using ajax

I am attempting to adjust the positioning of the scrollable list item depending on whether a message was sent by a user or another party. However, my current method is not yielding the desired results. I have experimented with adding .css('position&a ...

Customizing the CSS for individual posts in WordPress based on their post

I am interested in establishing a unique look for each individual post on my wordpress.org blog. Is there a way to customize the CSS code of individual posts without changing the design of other posts? I have tried using categories to create a new PHP fi ...

What are some effective strategies for repairing test automation code when using Selenium and C#?

Recently, I started delving into the realm of automated testing with Selenium and C#. Following the guidelines laid out for beginners in this resource, but encountered a roadblock. The tests are not running as expected, resulting in a failure. Below is the ...

Ensure the item chosen is displayed on a single line, not two

I've encountered an issue with my select menu. When I click on it, the options are displayed in a single line. However, upon selecting an item, it appears on two lines - one for the text and another for the icon. How can I ensure that the selection re ...

Initially encountering an error when launching the Protractor tool, however, it functions smoothly thereafter

Running "protractor_webdriver:start" (protractor_webdriver) task Initiating Protractor Webdriver Starting Selenium server: http://127.0.0.1:4444 Running "protractor:start" (protractor) task webdriver-manager path: E:\Work\Test&bs ...

Using jQuery to locate a JavaScript variable is a common practice in web development

I recently created a JSFiddle with buttons. As part of my journey to learn jQuery, I have been converting old JavaScript fiddles into jQuery implementations. However, I seem to be facing a challenge when it comes to converting the way JavaScript fetches an ...

Exploring the connection between Java Native Access (JNA)

While working on my project using Java on Linux, I attempted to incorporate a C library with JNA. However, I encountered an error when trying to map a native library file (.so). It seems like the issue lies in how I am mapping the functions. The specific ...

Ways to eliminate the top space in the background image

After implementing a basic HTML code to add a background image to my webpage, I noticed there is still some empty space at the top of the page. I attempted to adjust the position of the background image using the following code, but it only lifted it upwar ...

Is it possible to alter the page color using radio buttons and Vue.js?

How can I implement a feature to allow users to change the page color using radio buttons in Vue.js? This is what I have so far: JavaScript var theme = new Vue({ el: '#theme', data: { picked: '' } }) HTML <div ...