Utilizing Selenium and JavaScript to discover and extract the subject fields within a table

In my sent message list, I am trying to display the subject fields of all messages using Selenium and JavaScript (not Java) for coding.

Here is the code snippet:

<table class="messages">
    <tbody><tr class="section-heading">
      <th>
        <span class="screenreader-only">Delete</span>
      </th>
        <th>To</th>
        <th>Subject</th>
        <th>Sent</th>
    </tr>
  <tr role="row" id="message-k-s-10043496" tabindex="0" class="message"><td class="mark-for-delete keep-column">
  <div class="mark-container">
    <input type="checkbox" class="select-message" title="message-selection">
  </div>
</td>

<td class="message-metadata to">
  NKPContactMbrSvcs
</td>

<td class="message-metadata bottom">
  <div class="from mobile-only">
    From:  <span class="name">Sherlock Robin</span>
  </div>

  <div class="subject">
    Other Questions and Comments
  </div>

  <div class="from desktop-only">
    From:  <span class="name">Sherlock Robin</span>
  </div>
</td>

<td class="message-metadata keep-column">
  <div class="date-received">4:54 PM</div>

</td>

Image link for sent list

I have a limit of displaying 10 list items on the screen at once.

Answer №1

When creating multiple variables that are interconnected, it can be beneficial to group them together using JSON. For instance, you could have:

function register(username, password) {
Users = Users + 1;
userList['_' + Users] = {
    Username: username,
    password: password,
};

This approach allows for easy access to specific variables by utilizing a structured format like userList._1.username based on the username. The same principle can be applied in situations where you need a common identifier for emails. Here's an example:

email = {}
email[time] = {
    subject: subject,
    sender: sender,
    recipient: recipient,
    body: body
}

You might need to tweak this code as needed and encapsulate it within a function like so:

function email(sender, recipient, subject, body) {
    email = {}
    email[time] = {
        subject: subject,
        sender: sender,
        recipient: recipient,
        body: body
    }
}

Then, you can retrieve specific values by referencing them like this:

document.getElementById("HTMLid").innerHTML = email.(your time value).subject

Your HTML element could look something similar to this:

<p id="HTMLid"></p>

Answer №2

The topic field in the message appears like this

<div class="subject">

If you are looking for the CSS Selector div.subject, you might want to try something like this:

webBrowserElement.findElements(webdriver.By.css('div.subject'))

This should give you a good starting point for what you need.

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

Is it possible to selectively mock certain components of an external module using jest?

I am totally new to using Jest, especially in regards to unit tests, and I am struggling to write a test for a specific scenario. I know that you can mock an external module like this.. jest.mock('@organisation/library', () => ({ Database: j ...

When the disk space is insufficient, the createWriteStream function will not trigger an error event if the file is not completely written

One challenge I'm encountering involves using createWriteStream: Imagine I have a large 100mb file that I want to write to another file on the disk. The available space on the disk is only 50mb. Here's my code snippet: const fs = require(&a ...

Jest came across a surprising token that it wasn't expecting while working with React and TypeScript in conjunction with Jest and React-testing-L

An unexpected token was encountered by Jest while using React and TypeScript along with Jest and React-testing-Library. Error occurred at: E:\Git\node_modules@mui\x-date-pickers\internals\demo\index.js:1 ({"Object." ...

Making an HTTP request within a forEach function in Angular2

Encountering an issue while using the forEach function with HTTP requests. The _watchlistElements variable contains the following data: [{"xid":"DP_049908","name":"t10"},{"xid":"DP_928829","name":"t13"},{"xid":"DP_588690","name":"t14"},{"xid":"DP_891890" ...

Is it possible to evaluate the visual responses when interacting with an element?

Is it feasible to assess the visual response of an element during interaction? For instance, imagine there is a button on the webpage that visually becomes active a few moments after being clicked. Similar to the quick animation shown after clicking one o ...

jQuery carousel displaying a blank slide at the conclusion

I am experiencing an issue with my slideshow where it shows an empty slide after the last element. I suspect that there is something in my script causing this behavior, as it seems to be finding one extra child for the element and adding it as an empty spa ...

What is the method for inserting a line break into a string that is being transferred to a component in Next JS?

I am currently collaborating on a group project that involves developing a website. One of my team members created a ContentBlock component to facilitate the creation of new pages (see component code below). I have been working on a new page for the site a ...

"The controller's $scope isn't being updated within the DIV following a routing change

My website contains ng-view partials that change based on routing updates in $routeProvider. anmSite.config(function($routeProvider, $locationProvider){ $locationProvider.html5Mode(true); $routeProvider //Home page route .when("/", { temp ...

Selenium encountering difficulty in locating or interacting with element within dropdown selection

I've been struggling to choose a county in Florida from the dropdown menu available here. No matter what I attempt, I can't seem to locate or interact with any of the elements on the page. Every time I try, I encounter this error: NoSuchElementEx ...

I am experiencing an issue in my React application where the component is not being rendered when using a nested route with React Router Dom v6. Despite the

On my main page, I have a sidebar and a content display area that shows the selected option. The issue arises when I click on a link in the sidebar - it doesn't change anything in the content display section, only the URL changes. If I define the rout ...

Using jQuery to specifically target elements of a specific class that are nested within another element

I am currently using a jQuery function that toggles a drop-down navigation menu by changing its class when clicked: $(function () { $('.nav-titles').on('click', function() { $('.nav-dropdown').toggleClass(& ...

Unable to disable the download prompt in an Electron application to prevent popups while downloading a file

I've been attempting to use Selenium Chromedriver with Electron to download a file. I ran into an issue where I couldn't handle the popup window that asks you to select a folder for the download, so I attempted to bypass it like this: prefs.put( ...

Aurelia's navigation feature adds "?id=5" to the URL instead of "/5"

I have set up my Aurelia Router in app.ts using the configureRouter function like this: configureRouter(config, router: Router) { config.map([ { route: ['users', 'users/:userId?'], na ...

loop through an array and use splice to select items and modify the array

My current issue involves working with a pixabay array. Although I successfully retrieved the data from my array, it contains 20 random pictures when I only need 3 to be displayed on my website. I attempted to use a slice array for this purpose, but unfor ...

Utilizing the require function to implement an AngularJS Controller without having

I've been working with requireJS in my application. Every time I try to register a controller on my module, it gives me an error saying that the controller is not defined. Here's the code for my LoginController located in login.controller.js: f ...

Tips for converting JSON information on a website and inserting it into a designated division?

I've recently delved into front-end development, searching for solutions and hints without much success. I'm currently in the process of building my first website, specifically a "find recipes" website. Lacking knowledge of API calls, I created a ...

What is the most effective method for utilizing JSON as a database?

For my upcoming offline mobile web app project, I am considering using JSON to mirror some of my database tables and storing the data in localStorage. (Although Web SQL Database is an option, its future-proofing capabilities are questionable.) Initially, ...

Error message in Vuex4: Unable to access 'state' property because it is undefined

Having trouble with Vue3 and Vuex4, I keep encountering this error: Uncaught TypeError: Cannot read properties of undefined (reading 'state') at ReactiveEffect.eval [as fn] (App.vue?3dfd:36) at ReactiveEffect.run (reactivity.esm-bundler.j ...

The ElementNotInteractableException error occurred because the element cannot be interacted with as it is currently not visible, therefore it cannot be manipulated using robot framework

I am encountering an issue with a dropdown menu. When running the script, I receive the error message "ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be manipulated." Upon inspecting the HT ...

Exploring an array to retrieve a specific value

Can someone assist me? I am looking to create a JavaScript function that follows the structure of the code example below. Unfortunately, I do not have enough programming skills to develop a functional solution from scratch. The goal is to input a value, ...