0

I have been working on a Selenium project in Python where I want to choose the result which has a later timing than the earlier one but have trouble implementing it. What I meant is this,

Example

enter image description here

if I have a dynamic webtable with results of the same exact name(which in this case is job order number), how do I implement the function to choose the result which has been created the latest?

AutoTest.py

def __init__(self,driver):
    self.driver = driver

def testing(self):
    #For the 1st result with the same name with earlier timing
    result1_xpath = "//body[1]/div[1]/div[3]/div[1]/div[1]/table[1]/tbody[1]/tr[1]/td[8]/div[1]"
    #For the 2nd result with the same name with later timing
    result2_xpath = "//body[1]/div[1]/div[3]/div[1]/div[1]/table[1]/tbody[1]/tr[2]/td[8]/div[1]"

HTML Code

<table id="table" role="table" aria-busy="false" aria-colcount="10" aria-describedby="table__caption_" class="table b-table table-striped table-hover table-sm b-table-stacked-md"><!----><!----><thead role="rowgroup" class=""><!----><tr role="row" class=""><th role="columnheader" scope="col" aria-colindex="1" class=""><div>request id</div></th><th role="columnheader" scope="col" aria-colindex="2" class=""><div>job order number</div></th><th role="columnheader" scope="col" aria-colindex="3" class=""><div>status</div></th><th role="columnheader" scope="col" aria-colindex="4" class=""><div>requestor</div></th><th role="columnheader" scope="col" aria-colindex="5" class=""><div>approver</div></th><th role="columnheader" scope="col" aria-colindex="6" class=""><div>Total amounts ($)</div></th><th role="columnheader" scope="col" aria-colindex="7" class=""><div>Total Number of cards</div></th><th role="columnheader" scope="col" aria-colindex="8" class=""><div>Request DateTime</div></th><th role="columnheader" scope="col" aria-colindex="9" class=""><div>Update DateTime</div></th><th role="columnheader" scope="col" aria-colindex="10" class=""><div> Rejection Reason</div></th></tr></thead><tbody role="rowgroup"><!----><tr role="row" tabindex="0" aria-rowindex="1" class=""><td aria-colindex="1" data-label="request id" role="cell" class=""><div>101</div></td><td aria-colindex="2" data-label="job order number" role="cell" class=""><div>ecTesting2</div></td><td aria-colindex="3" data-label="status" role="cell" class=""><div>Topup_Completed</div></td><td aria-colindex="4" data-label="requestor" role="cell" class=""><div>zivwang</div></td><td aria-colindex="5" data-label="approver" role="cell" class=""><div>zivwang</div></td><td aria-colindex="6" data-label="Total amounts ($)" role="cell" class=""><div>4.00</div></td><td aria-colindex="7" data-label="Total Number of cards" role="cell" class=""><div>4</div></td><td aria-colindex="8" data-label="Request DateTime" role="cell" class=""><div>29/01/2021 15:32:04</div></td><td aria-colindex="9" data-label="Update DateTime" role="cell" class=""><div>29/01/2021 15:36:07</div></td><td aria-colindex="10" data-label=" Rejection Reason" role="cell" class=""><div></div></td></tr><tr role="row" tabindex="0" aria-rowindex="2" class=""><td aria-colindex="1" data-label="request id" role="cell" class=""><div>102</div></td><td aria-colindex="2" data-label="job order number" role="cell" class=""><div>ecTesting2</div></td><td aria-colindex="3" data-label="status" role="cell" class=""><div>Returned</div></td><td aria-colindex="4" data-label="requestor" role="cell" class=""><div>zivwang</div></td><td aria-colindex="5" data-label="approver" role="cell" class=""><div>zivwang</div></td><td aria-colindex="6" data-label="Total amounts ($)" role="cell" class=""><div>4.00</div></td><td aria-colindex="7" data-label="Total Number of cards" role="cell" class=""><div>4</div></td><td aria-colindex="8" data-label="Request DateTime" role="cell" class=""><div>29/01/2021 15:35:21</div></td><td aria-colindex="9" data-label="Update DateTime" role="cell" class=""><div>29/01/2021 16:44:41</div></td><td aria-colindex="10" data-label=" Rejection Reason" role="cell" class=""><div>Wrong top up amount</div></td></tr><!----><!----></tbody><!----></table>
4
  • is the result already sorted while displayed ?
    – PDHide
    Feb 4 at 10:53
  • nope. I tried to iterate it but to no avail
    – TechGeek49
    Feb 4 at 10:55
  • add website link or html
    – PDHide
    Feb 4 at 11:16
  • already added. Please take a look
    – TechGeek49
    Feb 7 at 6:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.