Discovering a collection of class elements with particular text in Selenium IDE

My objective is to verify that the correct title, summary, and link are displayed in search results. In the scenario below, I aim to ensure that one of the listings includes the title "Title for Beta," a summary with the content "Summary for Beta," and a hyperlink labeled "Link."

<ul>
  <li class="results">
    <h2 class="title">Title for Alpha</h2>
    <div class="summary">Summary for Alpha...</li>
    <div class="link"><a href="http://www.example.com">Link</a>
 </li>
 <li class="results">
    <h2 class="title">Title for Beta</h2>
    <div class="summary">Summary for Beta...</li>
    <div class="link"><a href="http://www.example.com">Link</a>
 </li>
</ul>

Answer №1

There are various methods for selecting elements on a web page. One approach is to utilize the CSS Class attribute.

HtmlUnitDriver driver = new HtmlUnitDriver();

driver.get("...");

List<WebElement> titles = driver.findElements(By.className("title"));
List<WebElement> summarys = driver.findElements(By.className("summary"));
List<WebElement> links = driver.findElements(By.className("link"));

for (WebElement webElement : titles) {
    String innerText = webElement.getText();

    // perform your desired actions....
}

If the page structure is complex, XPath can also be employed to locate elements.

For individuals new to Selenium, exploring the PageFactory Pattern is recommended as it promotes writing cleaner code.

In a unique approach, elements can be selected based on their InnerText using XPath. The following XPath selects all elements with "Title for Alpha" in their text content:

List<WebElement> titles = driver.findElements(By.xpath("//*[contains(text(), 'Title for Alpha')]"));

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

Modify the color of the background for a flex-wrap list

I am facing a situation where I have a list with an unknown number of items, but I need to control the height of its container. To achieve this, I am using flex-flow: wrap column to split the list. The list starts off hidden and is displayed using jQuery&a ...

Retrieve the content from an HTML table cell enclosed within a division tag

I am currently facing an issue where I need to extract the value from a specific div in order to proceed with the program. The value that I am trying to retrieve is '12345678'. <td id="TransaccionTesoreriaRetencionItems_NroComprobanteRete ...

Creating a floating border effect.Would you like to know how

Currently working on a new component, I'm looking to create a unique border for certain cards. However, I'm struggling to find the perfect solution. Check out the specific border style needed in the image provided below. https://i.sstatic.net/4vA ...

Menu toggle vanishes suddenly

Whenever I click the toggle button, I notice that the menu (which I have set to appear on toggle) only shows for a brief moment before disappearing. As a beginner in bootstrap, I am sure I might have made some obvious mistakes. Any assistance would be gr ...

Strategies for avoiding unused style tags in React components

Expanding beyond React, I'm unsure if React itself is the culprit of this issue. In a React environment with TypeScript, I utilize CSS imports in component files to have specific stylesheets for each component. I assumed these styles would only be ad ...

The CSS file is not updating

Recently, I updated an HTML file and the global CSS style sheet on my personal website. While the changes appear correctly on my computer, the website still reflects the old settings. I've taken several steps to troubleshoot this issue: Emptied my b ...

Exploring the theme color options in Angular Material

Despite extensive searching on SO and GitHub, I am seeking clarification: Is it impossible to access a theme color (or any other theme feature) in order to set a mat-card color? There is no way to retrieve a variable in scss. You cannot assign a class to ...

When trying to upload a file through input using WebDriver, the process gets stuck once the sendKeys

WebElement uploadInput = browser.findElementByXPath("[correct_identifier]"); uploadInput.sendKeys(elementPath); The script successfully initiates the file upload process, however, the custom JavaScript loading screen persists and fails to disappear as exp ...

Container will keep items from spreading out

Experiencing an issue with the card layout in my weather dashboard app. The cards within a container are not spreading out evenly to match the 100% width of the header. I want the container with the 5 cards to be the same width as the header and wrap prope ...

"Interactive bootstrap tabs nested within a dropdown menu that automatically close upon being clicked

Hey, I've got a dropdown with tabs inside. When I click on certain tabs within it, they close but the content inside the tabs that I click on changes, so it's functioning properly. However, the issue is that it closes when I want it to stay open ...

Adjust the width of the mosaic layout to a 50% / 50% ratio

I'm looking to adjust the layout so that each image occupies 50% of the page. Currently, one large image takes up 2/3 of the space and two smaller images take up the remaining 1/3. You can find the images here: To make the large image occupy 50%, yo ...

Guide to creating a Facebook post with Selenium Webdriver and Java

Is there a way to create a Facebook post using Selenium Webdriver and Java? This is the window I am referring to: http://prntscr.com/i603dv Below is the code I am using: driver.findElement(By.xpath("//input[@id='email']")).sendKeys("me-email") ...

Is there a way to position headline text behind another headline? Take a look at the image provided for reference

I need help creating headline text with a background image similar to the example below. I tried using relative positioning on the first heading, but I can't seem to get it to work correctly. If anyone can provide me with the code to achieve this ef ...

React JS Bootstrap Dropdown Troubleshooting

I'm facing a challenge in my React.js project while trying to implement a filter. The issue is that the list appears when I click on the button, but it doesn't disappear on the second click or if I click outside the list. Initially, I imported t ...

Utilizing Java.io FileUtils.copyFile with Selenium to generate dynamic names for destination files

How can I capture a screenshot and save it to a local folder using Java IO with WebDriver in Java? File screenshot = ((TakesScreenshot) driver) .getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot, new File("d:\\pic&b ...

Triggering animation with jQuery and CSS

I am working on a one-page site and I want to make a parallelogram disappear when a button is clicked for the next part. Currently, it is disappearing from right to left but I would like to change the direction to left to right. Additionally, I have a simi ...

Modify the main container width based on the size of the table

Would it be possible for the main container width to increase along with the table width? Is that achievable? <div class="container main-con"> <table class="table table-hover"> <tr><td></td></tr> </table> ...

Deploying a React application to Heroku or GitHub pages can sometimes alter the appearance of styles and CSS

As a newbie to coding, I've managed to create multiple full-stack apps, but I've encountered a frustrating issue each time I deploy them to Heroku or GitHub Pages. Every element on the page seems to shrink in size compared to what it was on my lo ...

Disregard IDs when linting CSS in ATOM

Is there a way to configure csslint in Atom to exclude "ids" and prevent the warning "Don't use IDs in selectors" from appearing? Update: Despite my question being flagged as potentially duplicate, I delved deeper in my own research and ultimately fo ...

Tips for properly formatting a fixed table header

I'm currently facing an issue with the sticky header style in my data table. I have created a simple Angular component along with a specific directive: sticky.directive.ts @Directive({ selector: '[sticky]' }) export class StickyDirecti ...