与标签名称关联的 Selenium Chrome Python 复选框

时间:2021-06-28 15:52:25

标签: python date selenium-webdriver checkbox label

我有一个网页,其中包含与日期(标签)相关联的复选框列表。

我希望能够解析网页:

  1. 在网页中找到我想要的日期,总是明天(今天 +1)
  2. 找到与找到的日期相关联的复选框
  3. 选中该复选框(例如:Baignade du 29 juin 2021)

目前,我使用 ID 找到我想要的 CheckBox 并点击它。

非常感谢您提前提供帮助。干杯。

链接: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()

image

0 个答案:

没有答案
相关问题