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

Issue with konvaJS when trying to simultaneously resize, drag, and apply filters to an image

Looking for help with resizing, dragging, and filtering images using Konvajs 2d canvas library? If the images are not resizing properly after applying a filter, can someone assist me? Note: Please be aware that when using Google image URLs, there may be c ...

Issues with triggering the success block in AngularJS and Node.js Express when using $http.get

As a beginner in the world of AngularJS and Node.js, I'm facing an issue with my $http.get method. The problem is that the success callback block does not get executed when the request is successful, whereas the error callback works just fine when the ...

Unable to retrieve value from a hidden input field using JavaScript

My goal is to retrieve a value from a hidden inputbox using JavaScript. However, I am encountering issues where sometimes I receive an "undefined" error and other times there is no output at all. When I utilize alert(document.getElementById('hhh& ...

"The AJAX response returned a status code of 200, however, the PHP script being executed on the XAMPP localhost did not provide

The HTML code initiates a localhost function called getNodes which returns JSON data that is verified by JSON lint. However, when the same function is invoked using AJAX from a JavaScript file, a 200 response code is received without any response data. I h ...

How to modify array in React using the useState hook?

Hello, I'm currently facing an issue where I am attempting to remove an object and set new data, but each time I do so, it reverts back to the previous state. For example, if I remove "emma" from the array ([ {name:"red"},{name:"reeed"},{name:"emma"} ...

Finding elements within a web page using XPath in Python with Selenium is proving to be a challenge."

I'm attempting to automate the process of downloading an iCal file from the website webuntis.dk using Python and Selenium. Currently, I have succeeded in having Python input the credentials for au_health on the login page. The next step is to click on ...

Can data from an Angular app be accessed by an external JavaScript code within the same project?

I've been thinking about a theoretical scenario that luckily I haven't encountered yet. Imagine I have an Angular Project compiled in My PROJECT FOLDER. <br/> Inside this PROJECT FOLDER, there's another JAVASCRIPT FILE external to ...

Adjust the hue as you scroll

I've been searching for a solution to this issue, but I haven't been able to make it work. My goal is to have the page header change from a transparent background to a red background as the user starts scrolling down the page. $(window).on("s ...

Looking to enhance the accessibility of a dynamically generated file by implementing the ability to expand and collapse sections as parent nodes

Currently working on a webpage where I am showcasing a testsuite file as the parent node and test cases within the testsuite file as child nodes. I have added checkboxes to both the parent and child nodes. Now, my goal is to include an ex ...

The search button is malfunctioning after I submit search data and generate dynamic HTML using axios

When a user clicks on the search button, I retrieve the input value and then use axios to send a GET request with the search data. Everything works fine, but when I query the database and dynamically create data from the mongoose data, the page reloads w ...

The module 'myapp' with the dependency 'chart.js' could not be loaded due to an uncaught error: [$injector:modulerr]

Just starting out with Angular.JS and looking to create a chart using chart.js I've successfully installed chart.js with npm install angular-chart.js --save .state('index.dashboard', { url: "/dashboard", templateUrl ...

Including a 3DS card to a Stripe Client for recurring payments

I'm encountering an issue when trying to add payment cards with 3DS authentication for existing customers who already have an active monthly subscription. The objective is to allow our clients to change, remove, and add cards to the Stripe Customer ob ...

Help with enabling the recognition of backspace key in JavaScript?

My current JavaScript is almost perfect but missing one key element. The form has two fields that are disabled when the user fills it out. <label>Can you drive? </label> <input type="booleam" id="drive" disabled><br> <label>W ...

I'm having trouble with AngularJS routes not functioning properly when accessed directly. I am using html5 mode in conjunction with

When accessing URLs directly in my Angular app either through the address bar or from external links, all routes default back to the home page. However, when navigating within the app, routes work as expected. I have come across similar issues on Stack Ov ...

Ways to center vertically aligned buttons within cards in a React application with Material-UI

I've encountered an issue with my ReactJS project using material-ui. I created 3 cards, each with a paragraph of varying lengths. This caused the buttons to be misaligned vertically in each card, as the position differs due to paragraph size differenc ...

Is it possible for Angular.js timer finish event not to trigger data binding correctly?

I've been working on an AngularJS application that functions as a quiz by displaying pictures and prompting users to select the correct answer by clicking a button. The app is designed to store the user's answers in an object. Everything seems t ...

Scraping Dynamic Content and Uncovering Hidden Data Tables with Selenium and Beautiful Soup

Seeking assistance from the community! I am currently working on web scraping Dynamic Content in Python using Selenium and Beautiful Soup. I am facing an issue where I am unable to parse the pricing data table into Python, even with the given code snippet ...

javascript the debate between inline and traditional registration

Hey there, I'm a JavaScript beginner and currently learning about inline vs. traditional registration. I've managed to get code block 1 (inline) working perfectly fine, but unfortunately, code block 2 (traditional) isn't cooperating. Can som ...

The Ajax request is not being triggered when using a different form submit method

Being a tech enthusiast, I have developed a handy function: function blur_slide_visit_count(){ $.ajax({ type: 'POST', url: 'add_save_slide_visitor_count.php', async: false, data: { fillvalue: fieldAr ...

Are you ensuring compliance with licensing in your Webpack bundles?

Can webpack be used to verify license compliance? I'm looking for a way to ensure that the license headers from all modules built by webpack are included in the final output file. How can we confirm this is happening? Furthermore, I am also intereste ...