[英]I am using Python and Selenium in order to automate site testing and cant get selenium to submit a form
[英]cant automate calendar in selenium python
我正在嘗試使用 selenium 自動化日歷,但找不到解決方法,日歷 html 的結構是這樣的:
6 個 div 包含每天的標簽,有些日子像這樣被禁用:
我對此的看法是,我將選擇所有未禁用的標簽並查看,如果 elem.text 等於我將在函數中作為參數提供的某個日期,selenium 將選擇該日期這是我的代碼為了這:
def pick_date(self, date, month, year):
month_status = WebDriverWait(self.driver, 10).until(
EC.visibility_of_element_located((By.XPATH, '//*[@id="caltitle"]')))
_month, _year = (month_status.text).split()
next_month_btn = WebDriverWait(self.driver, 10).until(
EC.visibility_of_element_located((By.XPATH, '//*[@id="next-month"]')))
all_active_dates = self.driver.find_elements(By.XPATH, '//*[@id="calweeks"]/div')
print(_month, _year)
for i, week_row in enumerate(all_active_dates):
for day in week_row.find_elements(By.XPATH, f'//*[@id="calweeks"]/div[{i + 1}]/a[not(@attr="caldisabled") and not(@attr="caloff")]'):
if day.text == date:
day.click()
print(day.text)
但是for day in week_row.find_elements(By.XPATH, f'//*[@id="calweeks"]/div[{i + 1}]/a[not(@attr="caldisabled") and not(@attr="caloff")]')
這是選擇所有 a 標簽,不僅非禁用輸出是這樣的:
June 2022
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
任何幫助將不勝感激,因為我在這個問題上抨擊了很長時間。
獲取所有活動元素:
all_active_dates = self.driver.find_elements(By.XPATH, f'//*[@id="calweeks"]//a[not(contains(@class,'caldisabled')) and not(contains(@class,'caloff'))]')
然后只需枚舉all_active_dates
並簡單地print(active_date.text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.