Home > database >  Get value from HTML TD Between Div
Get value from HTML TD Between Div

Time:07-19

I'm trying to get the value between the div, as I am trying to continue the program once the code has been introduced correctly. However I can't seem to get the value from the element. Value is in this case '12345678'

<td id="TransaccionTesoreriaRetencionItems_NroComprobanteRetencion_1" height="22px">
    <div style="width: 115px; overflow: hidden; cursor: pointer;">
        12345678&nbsp;&nbsp;&nbsp;
    </div>
</td>

Code image

CodePudding user response:

  1. get the td
let a = document.getElementById("TransaccionTesoreriaRetencionItems_NroComprobanteRetencion_1")
  1. get the divs inside the td
let b = a.getElementsByTagName("div")
  1. get the first div inside the list
let c = b[0].innerText

and you get

c
'12345678   '

CodePudding user response:

To print the text 12345678 you can use either of the following locator strategies:

  • Using css_selector:

    print(driver.find_element(By.CSS_SELECTOR, "td#TransaccionTesoreriaRetencionItems_NroComprobanteRetencion_1 > div").text)
    
  • Using xpath:

    print(driver.find_element(By.XPATH, "//td[@id='TransaccionTesoreriaRetencionItems_NroComprobanteRetencion_1']/div").text)
    
  • Related