• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Iterate through elements with no attributes using selenium python

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am scraping a website using selenium python to take an appointment. I click on the calendar to chose which date is available, and the available dates are on green.



HTML code of the calendar:


The available dates have the same attribute title, , so I made the following Xpath to find them,
It works, and I print them using a for loop:


Output:


When I click on a day, if there's an available time, I can continue filling the form normally, but when there is no time available during that day, it shows an error message
What I want to do is to iterate through those available dates, pick a time if it's available and continue filling the form. If there is no time available and it shows an error message, I want to go to the next date and repeat the process until I find an available time.

I made the following script to click on date 23, but I'm not sure if it's going to work or not because the dates are no longer available and I can't test it out.



The problem is that the available dates don't have any different attribute that I can locate them with, so I don't know how can I iterate through them. Each row is represented by tr attribute with an index from 1 to 6. And each tr has 7tds, for example, the Xpath of the date 23 is
I had the idea of appending the available dates in a list and iterate through it, but I can't do that because I can't locate them automatically. I'm really stuck at this point and I really need help. I hope I made what I want to do obvious.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You are trying to be too monolithic here. I prefer to break down code into functional elements. Makes it easier to understand and maintain.

As for knowing which day it is, the body text of the date element has that!
 
Goetia Dark
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:

You are trying to be too monolithic here. I prefer to break down code into functional elements. Makes it easier to understand and maintain.

As for knowing which day it is, the body text of the date element has that!



What I'm trying to do is to click on the available dates in sequence. But I don't know how to do that because the dates has no unique attribute.



The only thing that changes is the text.
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's something missing here. You cannot "just click" on a table element and have it do anything. There either has to be some JavaScript attached to it somewhere or you have to be using an image map form submit (which almost nobody does anymore).

So you need to find out what causes the magic when you click manually before you can automate it.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you find a solution? I am facing the same issue
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic