Selenium RC: Utilizing the CSS :contains pseudo-class for Element Selection

I have a task to verify that the data in a table row matches my expectations for two different tables.

Let's look at an example using HTML:

<table>
    <tr>
        <th>Table 1</th>
    </tr>
    <tr>
        <td>Row 1 Col 1</td>
        <td>Row 1 Col 2</td>
    </tr>
</table>

<table>
    <tr>
        <th>Table 2</th>
    </tr>
    <tr>
        <td>Row 1 Col 1</td>
        <td>different data</td>
    </tr>

In this context, the following assertion passes successfully:

$this->assertElementPresent('css=table:contains(Table 1)');

However, this assertion does not pass as expected:

$this->assertElementPresent('css=table:contains(Table 1) tr:contains(Row 1 Col 1)');

Ultimately, I aim to validate that both columns within the table row contain the anticipated data:

$this->assertElementPresent('css=table:contains(Table 1) tr:contains(Row 1 Col 1):contains(Row 1 Col 2)');
$this->assertElementPresent('css=table:contains(Table 2) tr:contains(Row 1 Col 1):contains(different data)');

What could be causing these issues? How can I resolve them?

Update:

It seems like the issue could be related to a bug in Selenium when trying to select descendants.

To work around this problem, I had to add an extra identifier to the table so that it could be uniquely identified:

/* HTML */
<table id="table-1">

/* PHP */
$this->assertElementPresent("css=#table-1 tr:contains(Row 1 Col 1):contains(Row 1 Col 2)");

Answer №1

It seems like there is a glitch in the CSS selector library that Selenium uses. To work around this issue, you can try the following solution:

css=table:contains(Table 1) > tbody tr:contains(Row 1 Col 1)

You can find more information about this bug here:

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

Build Agent encountering errors with locating elements on TeamCity using Watir-Webdriver and Selenium

Recently, I've encountered a persistent issue with reliability while running Cucumber\Watir-Webdriver (Ruby) tests on a TeamCity build agent. While executing the 96-step suite against the CI web app server from my local machine, all tests pass w ...

Are the nav, footer, header tags not functioning correctly?

Hi everyone, I'm a newcomer to StackOverFlow! I have a question about the necessity of tags like Nav, footer, header, etc. Do they serve any purpose other than indicating what each section is about? I've heard they might be good for SEO rankings ...

python-selenium clicking on specific coordinates: "error when adding different types"

I'm having an issue with my automated tests on Robot Framework where I need to click on specific coordinates on a map. Here is the code snippet that I wrote: def click_at_coordinates(pos_x, pos_y): actions = ActionChains(get_driver()) my_map ...

How can I turn off Angular Grid's virtualization feature, where Angular generates div elements for the grid based on height and width positions?

Currently, I am working with an Angular grid (ag-grid) that dynamically creates div elements in the DOM to display data as the user scrolls or views different sections. As part of my testing process using Selenium WebDriver, I need to retrieve this data fr ...

What could be the reason behind the failure of this :after element?

I am facing an issue with the preloader on my webpage where the animation is not displaying as expected. The animation should appear on top of a dark black background before the page fully loads, but it seems to be missing. The CSS for the animation works ...

Running a Selenium script in Firefox fails when executed with sudo privileges

I currently have a simple script that looks like the following. from selenium import webdriver from selenium.webdriver.common.keys import Keys # Initiate a new instance of the Firefox driver browser = webdriver.Firefox() browser.get('https://www.goo ...

the neighboring div sliding to the left causing the div not to expand with its content

I am trying to create a website similar to this one. When I click on the arrow, the left div collapses and the right one expands. However, the content of the right div does not expand as expected! Below is my HTML code: <div class="tools-bg"> & ...

Challenge with CSS3 Selectors

I'm struggling to understand why this code works: input[ type = "text" ]:last-of-type:focus{ border:1px solid red; } but this code doesn't work: input[ type = "checkbox" ]:last-of-type:checked{ border:1px solid red; } The example given with t ...

Enhancing Bootstrap Carousel with various effects

My exploration of the web revealed two distinct effects that can be applied to Bootstrap Carousel: Slide and Fade. I'm curious if there are any other unique effects, such as splitting the picture into small 3D boxes that rotate to change the image? ...

Is there a way to create a table with "cells that can be controlled individually" similar to the image provided using HTML and CSS?

I have been searching online for solutions on how to create a table similar to the one in this image, but so far I haven't had much luck. I attempted to use colspan, however, it didn't yield the results I was hoping for. Does anyone have any alt ...

Collect information from forms and save it to a mobile phone number

Is it possible to forward form field details to a cell phone number via text message? Here is the code I currently have for sending form data to an email address. If any adjustments need to be made, please provide instructions. <?php if(isset($_POST[ ...

Is there a way to drop a pin on the Google Maps app?

Is there a way to pinpoint the specific location on Google Maps? <google-map id="map-container" width="100%" height="100%" class="maps"></google-map> ...

Error message: testNG org.openqa.selenium.WebDriverException encountered an issue connecting to binary FirefoxBinary(C:..Mozilla Firefoxfirefox.exe) on port 7055

I urgently need assistance with a serious problem This morning, I encountered an error while running my script. It was working perfectly fine last night. When I turned on my computer and noticed that Firefox had updated to version 47.0, I ran my script on ...

What is the functionality of 'min-height: 100vh' when child elements stack due to a small width?

In a parent element, I have two child elements: <div id="registration"> <div id="left-panel"></div> <div id="right-panel"></div> </div> The styling is as follows: #registration{ @include l { flex-dire ...

Struggling to find the correct CSS path for the login input field

I am currently attempting to scrape a website that requires login credentials. However, I am encountering difficulty in obtaining the correct CSS-Path (or XPath) for the login form. The login page can be found here: When using Chrome: SelectorGadget on ...

JavaScript and Responsive Design Techniques

I'm struggling to create a responsive page that starts with a mobile-first approach, but I keep running into the same issue. When I have my dropdown menu in the mobile version, it looks good. However, when I try to switch it to the non-mobile version ...

Having trouble configuring the sticky-footer correctly

Currently enrolled in a web development course on Udemy, I am facing an issue with the footer on my webpage. Even after setting its CSS position to relative, the footer overlaps the content when more data is added. However, removing this positioning causes ...

Checking the opacity with an if/else statement, then adding a class without removing the existing class

This function is designed to check the opacity of the header, which fades out as a user scrolls down. If the opacity is less than 1, it disables clickability by adding the class "headerclickoff". However, there seems to be an issue with removing the clas ...

The CSS animation is functioning smoothly in Chrome, but unfortunately, it is not working in Firefox

I'm having trouble with my animation not working in Firefox and Safari, even though it works fine in Chrome. I've tried using the -Moz- and -WebKit- vendor prefixes, but it seems that Firefox and Safari already support the animation. CSS: .vi ...

Position the label to the left of the form-switch using Bootstrap

I have been struggling to align the label to the left of my switchbox. Despite searching through stackoverflow and other websites, I haven't been successful in achieving the desired alignment. Here is a trimmed down version of the code for reference: ...