Discovering if a web element includes a pseudo element in Java

Within my Java Selenium automation project, I am faced with the challenge of determining whether certain web elements contain pseudo elements or not.
I came across this question but found that the provided answer does not work as expected.
This solution seems more promising, although it involves locating an element which is different from my current scenario where I already have a web element and need to access its content.
As someone unfamiliar with JavaScript, my question is:
Given a Selenium WebElement object, how can I determine if it contains a pseudo element or not?
In the provided screenshot, one element shows a red dot representing the ::after pseudo element, while others do not have this indicator.
Even using dev tools, I cannot visually identify the pseudo element in the HTML code provided; it appears similar to other elements without pseudo elements.

<div workspaceid="49426bdc-59fe-44ec-82ea-8f567407c04f" data-test-id="9B1qjz0kWcfO" class="list-item ListItem__ListItemComponent-bsdtqz-0 dgogUS RoleItem-sc-1n184cw-0 jyfJwu role-item"><p class="text-component Texts__GenericText-sc-1dju4ks-0 czkGYX name p">9B1qjz0kWcfO </p></div>

Answer №1

If you want to utilize a WebElement as a parameter instead of a locator in the JavascriptExecutor, you have the option to do so. By using the getComputedStyle method, you can retrieve all CSS properties for the pseudo-element. To identify the red dot CSS property, inspect the CSS in devtools and then analyze it accordingly.

JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;

// JavaScript code to obtain any CSS property including pseudo-elements. 
// The arguments represent parameters passed to the executeScript method (standard Selenium functionality)
String js = "return window.getComputedStyle(arguments[0], arguments[1]).getPropertyValue(arguments[2]);";

// Instead of using a locator, employ a WebElement. 
// Here, we are looking for the "content" property as an example, but remember to investigate the CSS for the red dot
String cssProperty = (String) jsExecutor.executeScript(js, element, ":after", "content");

// Now check if the red dot CSS property is present

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

Invoke a Visual Basic program from a Java application

Can anyone provide guidance on the most effective method for calling a Visual Basic program from Java? I am in the process of developing a Java application and need to run multiple VB applications within it. ...

An effective method for using regular expressions to handle multiple line breaks

I need to efficiently search for double-spaces or more within large multi-gigabyte files. My goal is to achieve optimal performance when searching for multiple line feeds (newlines) using regular expressions. Is there a faster method than "\n{2,}"? I ...

Is there a way to refine a table based on the specific rows that are chosen in ag-Grid?

Is it possible to filter a table by rows with the attribute select: true, considering that select is not part of the data but rather an attribute of RowNode? I have tried using gridApi.getSelectedNodes() as well as text and number filters, but haven' ...

What could be causing my Vuetify v-select in Vue 3 to send [object Object] instead of the chosen value?

I'm currently tackling a Vue 3 project with Vuetify, and I've encountered an issue involving a v-select component. The selected value is appearing as [object Object] instead of its actual value. Here's a simplified snippet of my code: Pare ...

Combining smaa and ssao postprocessing in THREE.js magnifies the visual quality of graphics

I am attempting to merge SMAA and SSAO within my THREE.EffectComposer as shown below: this.composer = new THREE.EffectComposer(this.renderer); // Setting up depth pass depthMaterial = new THREE.MeshDepthMaterial(); depthMaterial.depthPacking = THREE.RGBAD ...

Submit form data to MongoDB upon submission

In my node express setup, I have integrated functionality to store values entered in checkboxes and text areas into a MongoDB database. Initially, users could calculate a score by clicking a button associated with checkboxes, and then post the information ...

Is there a way to confirm that every item in a list falls within a specified range?

I'm attempting to compare elements in a list with the locator value of 70.000. I have tried using AssertJ for this comparison, but unfortunately it's not working as expected: List<WebElement> priceList = driver.findElements(By.className(" ...

What is the best approach to including files in addition to other data fields when calling a webmethod in asp.net using a jquery ajax request?

My webform contains a variable number of textboxes and dropdowns. To send data to the server-side webmethod, I am utilizing the following code: $.ajax({ type: "POST", url: "SupplierMaster.aspx/RegisterSupplier", data: JSON.stringify({ ...

Transforming a JSON string into a Java array

Here is some JSON code representing an array: $info=array(); while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ array_push($info,$row); } $info; $result_final->lugares_cercanos = $info; Display this data: {"logstatus":"1","lugares_cercanos":[{"n ...

Selenium automated test execution is experiencing issues with enforcing restrictions on textboxes, such as special characters and numerals

During my testing of a web application, I encountered certain text fields that have restrictions based on specific requirements. For example, the Amount text field disallows alphabets and special characters, while the Name text field disallows numeric an ...

Why is it that when I use require.js, all my modules appear to be loading at once when the page first

During the development of my single-page backbone app using requirejs, I encountered an issue when deploying to our beta server. The initial page load took around 20 seconds as it had to fetch all the necessary scripts. I initially believed that this dela ...

Determine the latitude and longitude coordinates of the edges of the ground overlay based on the data in the

I am trying to determine the corner coordinates in latitude and longitude of a ground overlay provided in a kml-file using either php or javascript. For example, I need to convert from: <LatLonBox> <north>60.406505416667</north> ...

Guide on parsing a JSON document using Javascript

In my possession is a JSON file with the following data: [ { “name”: “Joshia \”Placement\” Fonz”, “color”: “white” }, { "name": “Trin Brin”, “color”: “black” }, { “name”: “Su Et ...

Close the menu in Angular 7 by clicking outside of it

I am seeking a way to detect when a click event occurs inside the parent div #menu, regardless of any HTML tags present within it. Using nativeElement.parent did not provide the desired result. Here is the HTML code: <button #toggleButton (click)="to ...

Sending a large base64-encoded file via Ajax POST using a mobile device

I have a Canvas where clients can sign a form on my website. The base64 string is sent through an AJAX POST to a Node.js server, and it works fine regardless of the file size when I run the process on my computer. If the signature is small, it can also be ...

The iron-session package does not export the path ./next/dist from the package

I am encountering an issue while using iron-session. Below is the code snippet causing the error: import { withIronSessionSsr } from 'iron-session/next/dist'; ... export const getServerSideProps = withIronSessionSsr(async function ({ req, r ...

Having trouble troubleshooting this issue where the object data is displaying in the console, but encountering an error when trying to use the resetValue

Index.html I am facing an issue while reading data from an object and the seek bar is giving a null error. The images and songs are stored locally, and I am trying to access them. <div class="music-player"> <div class="song&qu ...

What is the proper way to export .mtl files for objects on an iPhone 5 with ThreeJS?

I have been working on loading .obj files using ThreeJS for cross-compatibility. The OBJMTLLoader method works perfectly fine in Firefox, Chrome, and IE on Windows as shown on falloutfan.com/eyebot. However, when I try to view the object on an iPhone 5, i ...

Tips for extracting only key-value pairs with true values from an array of objects

I am working with an array of objects obtained from an API. The data received has multiple values, but I am interested in displaying only the access that a user has. For example, if a user only has read access, I want to display the read key. ...

Acquiring the visual representation of a component on a webpage using Selenium

On the website linked here, there is a central board that can be saved or copied by right-clicking on it. I am looking to create Selenium code that will allow me to retrieve this image. However, the board only consists of the following element: <canvas ...