[英]How to select a date from calendar using Selenium in python
[英]How to select a day in a calendar using Selenium on Python?
轉到https://lonnie-poole-package-plan-v2.book.teeitup.com/並單擊日期將我帶到日歷。 我能夠在月份和年份一直到達 select,但我不知道如何在我想要的那一天到達 select。 我知道我應該找到每天都遵循的通用 xpath 模板,但我不知道如何找到它。 任何幫助,將不勝感激。 這是我的代碼:
from selenium import webdriver
from config import keys
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from selenium.webdriver.support.select import Select
def order(k):
chr_options = Options()
chr_options.add_experimental_option("detach", True)
driver = webdriver.Chrome('./chromedriver', options=chr_options)
driver.get(k['website_url'])
time.sleep(1)
driver.find_element_by_xpath('//*.[@id="app"]/div/section/div/div/div/div[1]/div/div[2]/div/div/div[3]/div/div[2]/button').click()
while True:
text = driver.find_element_by_xpath('//*[@id="app-body"]/div[2]/div[2]/div[1]/div[2]/div[1]/div/p').get_attribute('innerText')
if text == k["month_year"]:
break
else:
driver.find_element_by_xpath('//*[@id="app-body"]/div[2]/div[2]/div[1]/div[2]/div[1]/button[2]/span[1]/span').click()
#issue begins here: this is where I am trying to select a day
driver.find_element_by_xpath('//*[@id="app-body"]/div[2]/div[2]/div[1]/div[3]/div/div[2]/div[5]/button/span[1][contains(text(),"20")]')
if __name__ == '__main__':
order(keys)
這適用於查找日期按鈕。
driver.find_elements_by_xpath('//button[@class="jss530 jss556 jss772"]')
只需將按鈕父級添加到帶有角色文檔的 div 中的日期文本的跨度。
driver.get('https://lonnie-poole-package-plan-v2.book.teeitup.com/')
wait = WebDriverWait(driver, 10)
#issue begins here: this is where I am trying to select a day
wait.until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/div/section/div/div/div/div[1]/div/div[2]/div/div/div[3]/div/div[2]/button"))).click()
day = 31
try:
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@role='document']//span[text()='{}']/parent::button[@tabindex='0']".format(str(day))))).click()
except:
print('Not valid date')
進口
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.