0

I have a Web browser's app UI Table as shown like this...

DATAPOINT           VALUE           STATUS
Output Voltage     95.0 VAC         Nominal
PS Input Voltage   15.0 VAC         Nominal
Inverter Status       Off           Nominal
Major Alarm        No Alarm         Nominal
Minor Alarm        No Alarm         Nominal

InnerHTML representation is something like this ...

tr[1] ---> td[1]      td[2]         td[3]
tr[2] ---> td[1]      td[2]         td[3]
tr[3] ---> td[1]      td[2]         td[3]
tr[4] ---> td[1]      td[2]         td[3]
tr[5] ---> td[1]      td[2]         td[3]

The above table is created by HTML Table like this ...

<table id="inventoryGrid1" class="table table-striped table-bordered dataTable no-footer" role="grid" style="width: 408px;">
  <thead>
  <tbody>
    <tr class="odd" role="row">
      <td>Output Voltage</td>
      <td>95.0 VAC</td>
      <td>
        <img src="../img/led/led_green.png">
        <span> Nominal </span>
      </td>
    </tr>
    <tr class="even" role="row">
      <td>PS Input Voltage</td>
      <td>135.0 VAC</td>
      <td>
    </tr>
    <tr class="odd" role="row">
      <td>Inverter Status</td>
      <td>Off</td>
      <td>
    </tr>
    <tr class="even" role="row">
    <tr class="odd" role="row">
  </tbody>
</table>

The Full xpath is ...

/html/body/div[2]/div/div/div/div[2]/div[2]/div/div/div/div[1]/div[1]/div/table/tbody/tr[1]/td[2]

I need to know ...

  1. I can't assign:
    row2col3 = drv.find_element_by_xpath("/html/body/div[2]/div/div/div/div[2]/div[2]/div/div/div/div[1]/div[1]/div/table/tbody/tr[2]/td[3]") # attempting to assign a variable to element in the table( row 2 column 3) which is "Nominal"

    Throws error: as 'list' object has no attribute ... Is it displaying that td tag name is a list ? and hence can't assign to a single variable ? Anyways, I am suppose to use row2col3 = drv.find_elements_by_xpath("/html/body/div[2]/div/div/div/div[2]/div[2]/div/div/div/div[1]/div[1]/div/table/tbody/tr[2]/td[3]") in order to get it working !

  2. If I use the row2col3 element I neither can use row2col3.text nor row2col3.get_attribute("innerHTML"). So how do I get this ? Is it even possible ?

How do I read out row2col3 particularly from the table ? Please forgive me for the long xpath implementation command and the bad english and also the long msg... :)

6
  • the 3rd td element of the 2nd tr element does not contain anything in your example -> did you forget to post sth? it's acutally not even closed correctly Commented Nov 26, 2015 at 11:03
  • When I copied the XPath from Firebug it was something like this for the second row and third column ..../tr[2]/td[3] at the end. Do you think, I am missing something here ? Commented Nov 26, 2015 at 13:49
  • yeah I think you're missing something in the html you posted -> your first row has a 3rd td element with an image and span, but your second and third row only have the opening of the td element, but nothing follows ... Commented Nov 26, 2015 at 13:50
  • ohhh that.... there were similar tag name td elements with span. I just hid that coz it would make the post much bigger ! :) But the UI table mentioned top would clarify the same... td[1] is associated to Datapoint, td[2] is associated to Value td[3] with span element would have STATUS. Every tr class is having the same sort of representation Commented Nov 26, 2015 at 14:05
  • ahh ok! So you want to extract the text "Nominal" or whatever is written in the other 2 span elements right? Commented Nov 26, 2015 at 14:06

1 Answer 1

0

value = findElement.byXpath("//tr[@class='even']//td[2]").getValue()

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply. but I am not sure if this works like total expectation. I have tried this too. The reason is, every alternate tr row will have even or odd class, hence if I use this way; the list of tr in the even rows will only be considered !
try: //td[text()='PS Input Voltage']/../td[2]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.