Getting an array of all visible text on a page using the same locator in Selenium

Within different sections of the webpage, I have utilized the following locator (excerpt from HTML):

<table id="userPlaylistTable" cellspacing="0" cellpadding="0">
   <p class="title"> ABC </p>
   <p class="title"> DEF </p>
   <p class="title"> GHI </p>

All of the items mentioned above share identical locators. How can I concatenate them into a string like "ABC DEF GHI"?

I aim to obtain this string because these elements are part of a table and follow a specific order within it. By comparing the obtained string after rearranging their order, I can verify if the reordering has occurred.

I attempted:

se.get_text("css=table#userPlaylistTable p.title")

However, this only retrieves the text of the first element, which is "ABC".

Are there any alternative methods to obtain the ordered text in a table as described above?

If possible, could someone assist me with the process? Thank you very much. Sunny

Answer №1

For those using RC, the following code can be helpful:

String s;
for(i=1;:i++)
{
String locator ="css=table#userPlaylistTable>p.title:nth("+i+")";
if(!selenium.isElementPresent(locator))
{
break;
}
String temp= selenium.getText(locator);
s.concat(temp);
}

This code involves iterating through the html code. If the locator is detected, the text is retrieved and added to the String s. If the locator is not found, the loop exits.

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

Do frameworks typically result in redundant CSS declarations?

Working on my latest Wordpress theme project, I have integrated the Bootstrap framework. One of the styles included in the Bootstrap CSS file is: input, textarea, .uneditable-input { width: 206px; } This style rule is causing issues with how my search ...

Executing PHP to control a Python Selenium script

I have a PHP script that triggers the execution of a Python script with Selenium. $command = escapeshellcmd("/home/clouduser/bots/telegram/send_alerts"); $output = shell_exec($command); echo $output; When I run Selenium outside of PHP, it works fine. How ...

Switch background color multiple times on click using JavaScript loop

Hello amazing people! I have a container with 52 small boxes and one large box containing a letter. The smaller boxes are arranged around the larger one using CSS grid, and when hovered over, they turn light grey. My Objective When any of the 52 small b ...

The footer should always be anchored at the bottom of the webpage, maintaining a consistent position regardless of any changes to the browser's

I've successfully implemented a footer with several buttons that remains positioned at the bottom of the page, 60px above the very bottom, regardless of the content or window size. The CSS I'm using is as follows: #container { min-height: 10 ...

After installing all essential plugins and drivers, I encountered an ERROR when attempting to run the Feature file

I'm currently using IntelliJ IDEA as my development environment. Despite having all the necessary plugins and drivers installed, I'm unable to pinpoint the reason for this error. Please refer to the code snippet provided in the image below: Ex ...

In what ways can the current theme be utilized to optimize spacing?

Greetings everyone, I need assistance with adding margins above and below a Button element. Below is the relevant code snippet: const useStyles = makeStyles(() => ({ progress: { display: 'block', margin: 'auto', }, })); ...

Is there a way to utilize PHP/HTML to exhibit a diverse array of random images as dynamic background visuals?

I'm currently learning the process of constructing a website. I've successfully constructed the index page, and below you will find the PHP and HTML code: <?php session_start(); $pngFiles = array('image1.png', 'image2.jpeg' ...

What could be causing this Ajax error I'm experiencing?

I am attempting to dynamically load pages on this website using JQuery and Ajax when a menu point is clicked. However, I am encountering errors during the loading process. What does the console message ""GET 'path to css file'" mean? (there ...

Selenium gets stuck when trying to navigate to a specific website using driver.get()

Lately, I've been struggling with a persistent issue that has me stumped as a beginner in web scraping. I'm trying to scrape various websites from a list using my Chrome driver, which usually works smoothly. However, there's one particular ...

Guide on incorporating a JS file in a React application

I recently obtained a template for my website that includes the following JS file which is being called from my React component. !(function($) { "use strict"; // Hero typed if ($('.typed').length) { var typed_strings = $(&quo ...

When my webpage is opened in Firefox, I notice that it automatically scrolls down upon loading

I recently embarked on the task of building a website from scratch but ran into an unusual bug in Firefox. The issue causes the page to scroll down to the first div, completely bypassing its margin. I want to clarify that I am not seeking a solution spe ...

Altering the PHP text hue

Is it possible to customize the color of the print and echo text on your HTML page, rather than having it just in black? Thank you. ...

Approach to Using Bootstrap 4 with Intl-Tel-Input

I've been attempting to integrate intl-tel-input with bootstrap 4, but I'm facing an issue where the placeholder for the input is not showing up. I've tried various solutions found online, but none of them seem to work. Here's my HTML ...

Convert all SASS code into CSS within a Nuxt project

I am currently tackling a project that involves using SASS for part of the code. However, I have made the decision to transition from SASS to vanilla CSS. My goal is to find a way to convert all SASS segments into CSS either programmatically across the ent ...

Combine linear and radial background effects in CSS styling

I am trying to achieve a background design that includes both linear and radial gradients. The linear gradient should display a transition from blue to white, while the radial gradient should overlay a polka dot pattern on top of it. I have been following ...

Removing HTML elements using Nightwatch and Node.js - Step-by-step guide

It appears that in the Nightwatch framework, there is no presence of a 'document' or 'window' object. Instead, there is a 'browser' object which serves a similar purpose. I attempted to utilize methods such as .getElementById ...

Is there a reason why the integration of OnsenUI with Vue using vue-onsenui and v-ons-segment is not functioning

I am experiencing an issue with OnsenUI and VUE vue-onsenui v-ons-segment. Instead of displaying a button bar in a row as expected, I am seeing standard buttons. The problematic code resides in a customized Monaca CLI project utilizing the minimal VUE tem ...

The element you are trying to click on is not clickable because it is being accessed using

I have encountered a strange issue: When I select an element using the following code: WebElement e1 = driver.findElement(By.xpath("//div1")); WebElement e2 = e1.findElement(By.xpath(".[@class='c2']")); e2.click(); I am unable to click on e2, a ...

What's the best way to navigate across by simply pressing a button located nearby?

Hey there! I'm new to JavaScript and I'm working on a shopping list page for practice. In my code, I can add new items to the list, but what I really want is to be able to cross out an item when I click the "Done" button next to it, and then uncr ...

What is the process for incorporating a dropdown field and editable field within a container?

Looking to create a unique setup by incorporating dropdown fields and editable text fields within a designated box, similar to the image provided. Any tips on how to successfully implement this design? https://i.sstatic.net/6tGMp.jpg ...