Identifying and handling overlay blockers using Selenium technology

Currently, I am conducting tests on a website that utilizes in-browser pop-ups to display details about objects. These pop-ups are occasionally modal, meaning they render the rest of the screen unusable and activate a gray transparent overlay that covers everything except for the pop-up. It is important for me to verify if this overlay appears as intended.

Unfortunately, I do not have sufficient knowledge regarding how these overlays are implemented to know where to look in the DOM for the specific properties controlling this feature. Therefore, I am seeking guidance from someone more familiar with configuring such overlays to help direct me to the correct location.

While one solution could be simply clicking a button to observe the outcome, I prefer to create a method that can be utilized consistently across the entire testing suite rather than creating separate checks for each scenario.

For those curious, I am coding in Java using Selenium.

Answer №1

Although this advice may be considered outdated, it could still prove beneficial to someone in need. I recently tackled a similar issue with our React website and successfully resolved it. Our solution involved utilizing the react-block-ui module to manage the blocking overlays.

The key to identifying a blocked element by an overlay lied in two distinct observations:

  1. The element resided within a specific div structure (referred to as "the overlay") that adhered to a particular naming pattern – in our case, section-overlay-X.
  2. This overlay was distinguished by a class attribute named av-block-ui when active.

If you have access to similar information or resources, then you can apply a similar approach. I devised a couple of utility methods to check if a given WebElement was obstructed by an overlay. If blocked, it would trigger an ElementNotInteractableException.

For those using Java, here's a snippet of the relevant code:

...
By SECTION_OVERLAY_ANCESTOR_LOCATOR = By.xpath("./ancestor::div[contains(@id, 'section-overlay-')][1]");
...

    private WebElement findUnblockedElement(By by) {
    WebElement element = driver.findElement(by);
    if (isBlockedByOverlay(element)) {
        throw new ElementNotInteractableException(String.format("Element [%s] is blocked by overlay", element.getAttribute("id")));
    } else {
        return element;
    }
    }

    private boolean isBlockedByOverlay(WebElement element) {
    List<WebElement> ancestors = element.findElements(SECTION_OVERLAY_ANCESTOR_LOCATOR);
    WebElement overlayAncestor = ancestors.get(0);
    String overlayClass = overlayAncestor.getAttribute("class");
    return !StringUtils.isBlank(overlayClass);
    }

You can review more details about my implementation at: https://bitbucket.org/snippets/v_dev/BAd9dq/findunblockedelement

Answer №2

While this solution may not be universal, I managed to tackle the issue by examining the overflow property of the body element. The specific type of modal I was attempting to navigate inhibited page scrolling when activated.

Answer №3

Although this question is quite old, it still pops up as the first result on Google when searching for a similar issue.

To tackle this problem, I utilized Javascript and implemented the following function every time I needed to check for visible elements:

function checkVisibility(element) {
    const rect = element.getBoundingClientRect();
    // Get the center coordinates of the element
    const x = rect.left + rect.width / 2;
    const y = rect.top + rect.height / 2;
    const topElement = document.elementFromPoint(x, y);
    return !element.isSameNode(topElement);
}

By combining this approach with Selenium's default visibility settings, I successfully interacted only with elements that were not obstructed by overlays.

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

Error: The Vue bind object property cannot be read because it is undefined in the class binding

I'm attempting to associate a class with an object property, but I encounter an issue when trying to trigger the @click event on the list object - the console states that it cannot read the isSelected property of the object. My goal is to activate a c ...

Why is it that Lotus Notes is unable to render this HTML code properly?

I am having trouble with an email that displays properly on every platform except Lotus Notes. Can anyone provide insight as to why this email is not rendering correctly in Notes? Here is a screenshot: img (please note the images are for demonstration pu ...

Impeccable method to safeguard element from external css interference

Currently, I am working on a script that will be utilized across various pages and I want to ensure that the elements it generates are not affected by the CSS styles of those pages. Some individuals suggest using CSS like this: body>*{min-height:200px; ...

Eliminate the header top margin in Bootstrap

HTML <div class="container-fluid"> <div class="row"> <div class="page-header header_site"> <h1><font>ABC Company</font></h1> </div> </div> </div> CSS Code: .header_site { b ...

Utilize the "display: flex" property to position an avatar alongside a comment that is wrapped

Looking for a solution similar to the problem presented in this Stack Overflow thread about positioning text next to an image, but specifically when using "display: flex". We are facing an issue where a comment, consisting of an avatar image and accompany ...

Is it achievable to use PHP to automatically scroll to the bottom of a container?

Is there a way to automatically scroll to the bottom of a div container using PHP code instead of javascript or CSS? While I haven't been able to find a solution using just CSS, I have come across some options utilizing javascript. However, since I a ...

explore the route with the help of jquery scrolling feature

Is there a way to implement scrolling functionality for tab headers similar to this demo? I have a list of elements within a div that I need to scroll like the tabs in the demo. I attempted to achieve this by setting the position of the inner elements to ...

Limit the radius to only apply on big screens using tailwind css

Is there a way to apply border radius to an image only on larger screens and maintain straight edges on smaller screens? I'm working with Nextjs and Tailwind CSS. ...

Enhancing visual aesthetics with Vuetify on v-slot label components

I am working with Vuetify code that appears like this <v-radio-group v-model="gender" column class="radio-group-full-width"> <v-radio value="Boy"> <template v-slot:label> <v-textarea v-model="answer" v-vali ...

Having trouble locating the source of the issue causing the product page to appear too wide on Shopify

Can someone assist me in identifying the issue that is causing the product page on this website () to be too wide? Here is an image highlighting the issue. I made some CSS customizations to make the product gallery full width and added padding to the pro ...

Fixing the Overflow Property in CSS

I just started learning about css, and I've encountered a problem with the code for the overflow property: div.hidden { background-color: #00FF00; width: 1000px; height: 1000px; overflow: hide; } ...

What is the best way to improve the design of this division that includes buttons?

I'm having trouble with the layout of three divs I have set up. One acts as a container, while the other two are meant to hold buttons. However, something seems off and I can't figure out how to correct it. .button { display: inline-block; ...

One of the iterations encountered a Selenium TimeoutException error

wait = WebDriverWait(driver, 20) #waiting for 20s to allow webpage loading driver.get('https://beta.clinicaltrials.gov/') #navigating to website URL driver.maximize_window() time.sleep(1) country = wait.until(EC.element_to_be_clickable((By.XPA ...

Using Crawler4j, Jsoup, and JavaScript to retrieve modified attribute values

Currently, I am utilizing Crawler4j and Jsoup for web crawling and it's performing well with HTML text. However, some vital contents have default values hardcoded in CSS and then dynamically adjusted through JavaScript. For instance, there's a e ...

Encountered difficulties initiating a new session with Selenium WebDriver

I am attempting to launch the Firefox browser using Selenium Java code. System.setProperty("webdriver.gecko.driver", "C:/Program Files/Mozilla Firefox/geckodriver-v0.8.0-win32/geckodriver.exe"); WebDriver driver = new FirefoxDriver(); System.setProperty( ...

Image of outer space enclosed by a circular boundary

Check out this fiddle I created here. It's a simple concept of an image inside a red circle. Is there a way to add some spacing around the image within the circle? This is the markup I currently have: <div style=" width: 50px; he ...

Employing JavaScript for fading divs in and out sequentially

Hey there! I'm currently struggling with implementing transitions for my tool tips. Any assistance would be greatly appreciated! I am looking to have my "fader" divs fade in and out on click of a button, with each transition lasting 5 seconds. It&apo ...

How to Create a DataTable Responsive Feature Where All Columns Collapse on Click, Except the Last One?

I am currently utilizing the DataTables library to generate a responsive table. I am aiming to create a feature where all columns in the DataTable can toggle between collapse and expand states when clicked, with the exception of the last column. Below is a ...

Finding a button within a child div using Python and Selenium

My goal is to click a button that does not have an ID or a unique class name and can only be located through child divs. The button text reads "Export to GPS Device," but it is actually situated within a div below. View Screenshot I have attempted the fo ...

Webpage unable to scroll

Having trouble with scrolling on my webpage and I can't figure out why! The issue is happening when trying to view this page: Within the main file, I have included 2 other php files: <?php include '../../include/menu.php'; inclu ...