1

I have a sent message list and in that I want to print all the message - subject fields. I am using selenium and using javascript (NOT JAVA) to write the code.

The code is :

<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 for sent list

I have maximum of 10 list items displayed in the screen.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • What have you tried and what was the result? As you did in school... please show your work. :) It's part of the process of getting questions answered on SO. It's helpful to you because it forces you to investigate your own problem and think it through. It also proves to readers that you did your homework and made a reasonable attempt to answer your own question. Thirdly, it helps readers find and diagnose the problem resulting in a better answer for you and less time wasted for us. – JeffC Nov 05 '15 at 02:03
  • Hey Jeff, I tried $('.messages tr .message') but it is printing only the first message in the list. When I tried $('.messages tr:nth-child(2) .message') I am getting the 3rd row from the list. – Ruthvik Yedla Nov 05 '15 at 02:39

2 Answers2

0

when you are making so many variables that are related to each other, it may be a good idea to jumble them into the same variable using JSON, for example you may have

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

this allows you to use things such as userList._1.username to access the variable you have based on username the same concept can be applied to your problem where you have a base value you want to use for identifying the email. an example of this may be

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

this code may require so fiddling with and you can bunch this into a function to create

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

and then you can use

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

with you html showing something like

<p id="HTMLid"></p>
puppy0cam
  • 51
  • 5
  • This doesn't really answer the question but it does contain valuable advice. I would definitely recommend using a javascript object literal to store like data... all the data on a particular email, for example. While they look the same JSON and an object literal (what you call a JSON in your answer) are not the same. Please read this [SO Q&A](http://stackoverflow.com/questions/2904131/what-is-the-difference-between-json-and-object-literal-notation) for more info. – JeffC Nov 05 '15 at 03:02
  • One more thing... you are going to have issues if you use time value as an index. There's nothing to say that two emails won't come in at the same time and have the same time stamp. That's going to throw a wrench in your storage method. You could deal with that by appending an index to the end of each time to differentiate them though... – JeffC Nov 05 '15 at 03:04
0

The message subject field looks like this

<div class="subject">

So what you want is the CSS Selector div.subject. I don't use javascript/selenium but I think what you want is

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

That should at least point you in the right direction.

JeffC
  • 22,180
  • 5
  • 32
  • 55