What is the NOT selector used with the CSS contains function for?

I have a question regarding my Selenium code. I am currently using the following snippet:

WaitForElement(By.CssSelector("#document-count:contains(<number greater than 0>)"));

The part where I'm stuck is specifying number greater than 0. Is there a way to use CSS alone to verify if an element's inner text contains a value other than 0?

Answer №1

:contains became outdated in the CSS3 version. Due to the direct connection between WebDriver and the browser, it is unable to utilize that particular pseudo-class.

Is there a way to solely use CSS to verify if an element's inner text contains anything other than 0?

Regrettably, no. The deprecation of both :contains and :nth by CSS has posed challenges for Selenium users.

As mentioned by Arran, one alternative solution could involve utilizing xpath, or - with a willingness to explore combining C# and CSS (not just css as initially suggested) - devising a script to iterate through content checks multiple times.

Answer №2

As per Chris Coyier's insights on CSS Tricks:

Outdated Information

:contains() - It seems that this feature no longer exists in the current CSS3 specifications. The ability to select elements based on their text content seemed incredibly useful. It is possible that it was removed due to issues or simply because having content in selectors may not be ideal. Personally, I would have preferred a selector based on elements rather than text, like p:contains(img), but unfortunately, that option is not available.



However, if you set the value properties correctly, you could potentially use :not([value="0"]):

View the demo on jsFiddle



HTML

<div id="doc">
    <input type="text" value="0" />
    <br />
    <input type="text" value="1" />
    <br />
    <input type="text" value="2" />
</div>


CSS

#doc input[value="0"]
{
    background: red;
}

#doc input:not([value="0"])
{
    background: green;
}


Result

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

Method for capturing a screen grab in cucumber using a tag name

The code snippet below is written in Selenium/Java, and my goal is to parameterize it by adding the tag name for which the screenshot needs to be taken: @Then("^Take Screenshot$") public void tearDown() { // Take a screenshot at the end of every tes ...

Enhancing user experience with CSS dropdown menu animations

I've been working on adding a dropdown transition to my menu, but I can't seem to get it right. Can anyone point out where I'm going wrong or what needs to be added for the transition effect on the dropdown menu? Here is the CSS and HTML cod ...

How to extract text from outside a tag using Selenium in Python3 with Chrome?

I am having trouble extracting text from outside of a tag. Currently, I am working with Python3.7 and I have experimented with both Selenium and BeautifulSoup4. Below is the HTML snippet I am dealing with: <br> <span class="label">Max. Allo ...

Issue with loading the main.css file

Getting Started Managing two domains can be a challenge, especially when trying to make them appear as one seamless website. In this case, I have ownership of and . Goal My goal is to merge the content of https://mauricevandorst.com/personal-page/index ...

The submit button on the HTML form is not functioning properly and requires activation

Currently, I am a student focusing on honing my skills by working on an app for a blog post. To kickstart my project, I downloaded the "clean-blog" template from the startbootstrap website. If you are interested, here is the link to the template: My curr ...

Is it possible to incorporate a similar box on a webpage?

I am trying to find a way to add a similar box to a webpage like the one shown in this image. The design I am referring to is from Reddit's theme, but I would like to know how to create a box with a different color and then have another box next to i ...

Revamping Existing Styles: Making a Statement with `:after`

In my asp.net mvc application, I am facing an issue where the * symbol, representing a required field, and the ? symbol, representing help, are not both being displayed. The ? symbol seems to be overriding the * symbol, resulting in only one symbol being s ...

Information about the driver: driver.version currently unknown, operating with ChromeDriver v78.0.3904.70 and Chrome browser v78.0.3904.97

Currently, I am running Java 1.8 on Chrome browser version 78.0.3904.97. In my Selenium script, I am using the Chrome driver version 78.0.3904.70. Unfortunately, during execution, I encountered an issue where Chrome crashes immediately. Picked up JAVA_TOO ...

What is the best way to position this material-ui select list at the bottom of the input block for proper alignment?

My material-ui select build is working fine overall, but I'm looking to align the top line of the select list with the bottom line of the input block. Any ideas on how to achieve this? This is my code: const styles = theme => ({ formControl: { ...

Tips on skipping certain steps in the Background section of a feature file for specific scenarios in Selenium using Java

Is it possible to prevent the second step in the Background feature from running for the second Scenario? Any suggestions on how to achieve this? Background: Given Do given And Do this(No need to run for the second scenario) And Do this Scenario: U ...

Does the color of the item change as it gets older?

How can I smoothly transition a color as it ages using a dynamic time scale? I want to calculate the age based on the difference in time rather than triggering an animation after an event. I aim for a seamless gradient transition between two colors over a ...

The application of border-radius causes the div to extend beyond its intended height

Is there a way to achieve a smooth shadow effect on pictures without it touching the corners? I attempted to do this by adding a border-radius and box-shadow to the parent div of the images, but now the parent div is taller than the picture itself. Any sug ...

Interactive text that changes when hovered over in an HTML document

My table contains text and I have implemented code that displays a small text when hovering over it. I would like the entire column to trigger the text display on hover, ideally in a larger size. Any suggestions on how to achieve this? ...

Can someone help me troubleshoot the issue with my submit button's onclick function?

I am currently working on a project where I have a content box enclosed in a div tag. Within this content box, there are paragraphs with unique IDs for individual styling rules. I have set margins, padding, and other styles accordingly. At the bottom of th ...

CSS-only Modal (Utilize CSS to display or conceal a row upon hover of the preceding row)

Is it possible to create a hover effect in CSS that collapses or shows a table row when hovering over the previous row? I'm looking to display additional information on hover over a specific row in a table. ...

Aligning variable width numbers within a div container

Currently experimenting with CSS to create a calendar design that mimics the look of a traditional paper calendar. One issue I've encountered is the alignment of numbers within boxes, especially when dealing with double digits. When displaying a sing ...

Spacing issues with inline-block elements when dealing with a large quantity of items

Currently, I am tackling the JS/jQuery Project for The Odin Project and I am confident that my solution is working exceptionally well. However, the issue I am facing is that when dealing with larger amounts of elements (around 40-45 in JSFiddle and 50-52 ...

The side menu in Bootstrap dropdown experiences a one-time functionality

When navigating through a responsive top menu with Bootstrap, everything works seamlessly - from toggling the menu to dropdown functionality. However, I encountered an issue with the side menu as nav-pills used to select tab-panes. <div class="containe ...

The input-group-btn is positioned to the right of the field, appearing to float

The input-group-btn for the targetDate field remains fixed on the right side of the input group despite screen width variations until I introduce the automatically generated CSS from the hottowel generator. I require assistance in identifying which aspect ...

Guide on altering the Class with jquery

Here is My jQuery Code: $('a#cusine1').on('click', function(){ $('div#product-list').html("LOADING..........").show(); $(".ccid").addClass("0"); document.getElementById("ccid1").className="acti ...