lundi 28 juin 2021

Selenium Chrome Python checkbox associated with a label name

I have a webpage with a list of checkboxes associated with dates (labels).

I want to be able to parse through the webpage :

  1. Find the date I want in the webpage which is always tomorrow (today +1)
  2. Find the Checkbox associated with the found date
  3. Check that checkbox (ex.: Baignade du 29 juin 2021)

For the moment, I use the ID to find the CheckBox which I want and click on it.

Thank you so much for your help in advance. Cheers.

LINK: https://ludik.maville.net/Brossard-LudikIC2Prod_Enligne/Pages/Anonyme/Recherche/Page.fr.aspx?m=1

# piscine Reservation Alpha v1
# https://sites.google.com/a/chrominium.org/chromedriver/downloads
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

import time
import datetime


PATH = "/Users/josephhuynhngoctri/Desktop/Python/chromedriver"
driver = webdriver.Chrome(PATH)
action = ActionChains(driver)  # init. action for double-click

# get Web page Brossard for aquatic activities
driver.get("https://ludik.maville.net/Brossard-LudikIC2Prod_Enligne/Pages/Anonyme/Recherche/Page.fr.aspx?m=1")


# click on "Aquatique" button at the top left menu
link = driver.find_element_by_id("ctlHautPage_ctlMenu_ctlLienActivites")
link.click()

time.sleep(2)

# CHOOSE DATE
# select checkbox 29 Juin by ID - choice #10
checkbox = driver.find_element_by_id("ctlBlocRecherche_ctlRestrictions_ctlSelSession_ctlListeSessions_ctl10_ctlSession_ctlSelection")
checkbox.click()

# Find TOMORROW Date
today = datetime.date.today()
tomorrow = today + datetime.timedelta(days = 1) 
tomorrow = tomorrow.strftime("%B %d, %Y")
print("Today's date String =", tomorrow)

# select checkbox 29 June by xpath via label 
checkbox = driver.find_element_by_xpath("//label/input[contains(..'tomorrow')]")
checkbox = click()


  [1]: https://i.stack.imgur.com/FKJcM.png



Aucun commentaire:

Enregistrer un commentaire