python - 与标签名称关联的 Selenium Chrome Python 复选框
问题描述
我有一个网页,其中包含与日期(标签)相关的复选框列表。
我希望能够通过网页解析:
- 在永远是明天的网页中找到我想要的日期(今天+1)
- 查找与找到的日期关联的复选框
- 选中该复选框(例如: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()
解决方案
推荐阅读
- google-chrome - 在 Firefox 扩展中收到响应后,使用 requestId 检索请求
- qt - 如何从我的 qt 安装程序绕过 Microsoft Defender?
- python - 无法“激活” virtualenv
- bash - 期望脚本调用 bash 脚本,输出可能不会发生
- c++ - 浮点类型作为 C++20 中的模板参数
- devops - 设置 DevOps 默认项目集合
- reactjs - 反应 useState 重新渲染
- java - Quarkus 测试中的嵌入式 postgres 无法连接
- c# - 如何从数据视图中选择单个分组列?
- reactjs - 无法删除firebase / firestore中数组内具有确定值的对象