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

Selenium is unable to establish a connection to the HTTPS URL due to the absence of the SSL module

Having an issue with my anaconda environment and selenium. When I attempt to execute the code, I encounter the following error: Traceback (most recent call last): File "c:\Users\Nick\Desktop\Code\product-scraper\sep ...

The Chip Component in MUI dynamically alters its background color when it is selected

Currently, I am working on a project in React where I am utilizing the MUI's Chip component. My goal is to customize this component so that it changes its background color when selected, instead of sticking to the default generic color. https://i.sta ...

IE Browser is unable to retrieve elements

I encountered an issue with elements not being retrieved in the IE browser, specifically when using IE 11. When running my code, an error message appeared in my console: Started InternetExplorerDriver server (32-bit) 2.47.0.0 Listening on port 20577 Erro ...

Strange rendering in CSS JQuery Datatable

I am encountering an issue with a DataTable from datatables.net. Each row can be selected by clicking on a checkbox, which triggers a click event. In response to the event, I add or remove a CSS class to change the appearance of the selected rows. $(".cbD ...

Tips for adjusting the search bar's position on a mobile device when it is activated by the user

I need help with an open source project where I am developing a search engine using Angular. When using smaller screen sizes, the search bar is positioned in the middle but gets hidden behind the keyboard terminal when clicked on. Can anyone advise on ho ...

The behavior of Webdriver Selenium can vary depending on the computer it is running

Having written a piece of code to automate tasks using the Webdriver in C#, everything seemed to be running smoothly on my personal computer. However, a perplexing issue arises when the same code behaves differently on my boss's PC. The elusive eleme ...

Learn the steps to successfully rotate the custom icon in Material-Ui select without impacting its functionality and making sure it remains clickable

I've been trying to incorporate my own icon for the material UI select component. I successfully replaced the default icon using the "IconComponent" attribute in MU select. However, I'm facing issues with the new icon not rotating when the menu ...

Tips on utilizing browser scroll for horizontal overflow of internal div?

I'm working on creating a dynamic page with a tree-like structure that easily exceeds the width of the browser window. My goal is to enable horizontal scrolling for the entire page using the browser's scrollbar, without needing a separate scrollb ...

To access a website, I must navigate to the login page and click on the login button. This action triggers an Ajax call. What is the most effective way to

When needing to click on a login button within a website that triggers an AJAX call, what is the optimal method for clicking the element? Is it best to use Webelement.click() or Javascriptexecutor? ...

Stop unwanted overrides of CSS3 blinking background colors

I am facing an issue with a programmatically created table that has n rows. To distinguish between odd and even rows, I programatically add classes to them. Some of these rows have "special" content that needs to be highlighted. Currently, I am accomplishi ...

Customizing Mat Horizontal Stepper Icons with Unique Background Colors in Angular Material

I'm having trouble customizing the colors of the icons In my mat-horizontal-stepper, I have five mat-steps (Part A, Part B ... Part E), each needing a different color based on certain business rules. While I can change the color for all steps or the ...

Css styling for text highlighting

It's been some time since I encountered a CSS problem, but here I am facing one. In short, I want to highlight text with a gradient background, which I managed to achieve using the <span> tag and setting a background image on it. However, I ran ...

Mobile view doesn't quite center using flexbox, even though it works fine on desktop

Utilizing flexbox, the two distinct sentences that form the content of the page are centered. However, upon viewing the website on my mobile phone, the second sentence appears aligned to the left side. Here's how the site appears on a phone I've ...

I'm feeling lost trying to figure out how to recycle this JavaScript function

Having an issue with a function that registers buttons above a textarea to insert bbcode. It works well when there's only one editor on a page, but problems arise with multiple editors. Visit this example for reference: http://codepen.io/anon/pen/JWO ...

The two items are not situated side by side

Trying to make my page responsive, but when I inspect and look into mobile view, the elements do not align next to each other like they do on desktop. https://i.sstatic.net/8WhxD.png I want the shopping cart icon and button to be positioned next to each o ...

Is it best to stick with a static page size, or

While I typically design my webpages dynamically by determining the screen size and creating divs accordingly, I'm curious about the advantages of using a 'static' sizing approach (such as using pixels). Any insights on this contrasting meth ...

What is the best way to showcase two div elements side by side within my carousel

/* Implementing slideshow functionality */ var currentIndex = 0; displaySlides(); function displaySlides() { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); for (i = 0; i ...

What is the best way to create a footer in this scenario and is there a method to perfectly center an

What is the best way to position the footer at the bottom of the page without overlapping the top content? Is there a method to center both the height and width of the header element on the page? Can you review the layout of this webpage and provide feed ...

"Utilizing Box elements, implementing linear gradients, styling with CSS, and

Currently, I am working on a project that involves using react JS and I am trying to find a solution for implementing linear gradient in multiple boxes. Specifically, I want to achieve the effect of having three identical boxes lined up next to each other. ...

I am confused by these mysterious folders that appeared in my Eclipse workspace while working with selenium/cucumber

I've recently started using Eclipse and wanted to create a small test case as a Maven project with cucumber functionalities. However, every time I run the code, two folders are automatically generated: 1. Target/generated-sources/annotations and 2. Ta ...