0
rwdata = driver.find_elements_by_xpath( "/html/body/div[2]/div/div/div/form[2]/div[2]/table/tbody") 

This is a table, with the value of r with type text/javascript

for r in rwdata: print(r.text) if r.text != "Booked": print("Aceptado") 

When I print R it has the following values: Booked Booked Booked 9:00 AM Booked Booked Booked 2:00 Am Booked

¿How can I make this comparison, because so far it never enters the if?

 <td scope="row" headers="2/8/2021" class="timetable-cells"> <div class="cellcontainer" style="height:120px"> <div data-function="timeTableCell" data-sectionid="153" data-servicetypeid="862" data-fromdatetime="2/8/2021 9:00:00 AM" class="pointer timecell text-center " style="top: 0px; height:118px; background-color: #FF0000;color:#000000;" aria-label="Booked" role="row"> <label for="ReservedDateTime_2/8/2021 9:00:00 AM"> Booked </label> </div> 

    1 Answer 1

    1

    You're never entering the if because you're only checking the tbody elements textr value. So the entire string is "Booked, Booked, Booked, 9:00 AM, Booked, Booked, Booked, 2:00 Am, Booked". I think what you WANTED to do was loop through the individual cells? Like this:

    #here you fetch all the ONE element that are selected by xpath: rwdata = driver.find_element_by_xpath( "/html/body/div[2]/div/div/div/form[2]/div[2]/table/tbody") #here you loop through all those table TD elements for r in rwdata.find_elements_by_xpath("//td"): #here you print the TD's text value print(r.text) #here you check if the text value is equal to a short string if r.text != "Booked": print("Aceptado") 
    6
    • No, if you print one by one. Booked/n Booked/n Booked/n 9:00 AM/n ...CommentedFeb 1, 2021 at 20:48
    • What happens is that r is text / javascript, and I am comparing it to a string. How do I make this comparisonCommentedFeb 1, 2021 at 20:52
    • Sorry, I do not understand.
      – DMart
      CommentedFeb 1, 2021 at 20:55
    • @SebastianC I see that those table sells in your first comment are "Booked/n"...the code here is attempting to match "Booked" (without the /n"). You can modify DMart's code to strip the white space, then compare to your string. If that does not work please edit your question to include the html of the table that you are attempting to work with.CommentedFeb 2, 2021 at 11:38
    • Already edit the answer, I put a field of the column in html, the problem is not the spaces, the problem is that they are not of the same type as I mention in the comments above. How could I extract this text without problems or the color of this cell thanksCommentedFeb 3, 2021 at 19:22

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.