我想使用selenium单击一个按钮,并在站点的下拉日期选择器上选择该按钮
The button I wish to click is highlighted in yellow
我正在使用以下xpath
//*[@id="datepicker-1361-7562-title"]/strong
这是我正在使用的代码
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 datetime import date
import time
#calculating days from first day
d1 = date(2020, 3, 10)
dCurrent = date.today()
daysElapsed = int((dCurrent - d1).days)
#setting up driver and fetching website
driver = webdriver.Chrome()
driver.get('http://covid.gov.pk/stats/ict')
#wait for page and resources to load
WebDriverWait(driver, 25).until(EC.invisibility_of_element((By.XPATH, "//div[@id=\"preloader\"]")))
WebDriverWait(driver, 15).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//*[@id="app"]/div[2]/iframe')))
driver.find_element_by_xpath('//*[@id="body"]/div/div/div[1]/div[2]/div/div[1]/div[1]/div[1]/div/lego-report/lego-canvas-container/div/file-drop-zone/span/content-section/canvas-component[29]/div/div/div/div/ga-date-range-picker/lego-date-duration-control/control-layout-wrapper/button/div').click()
time.sleep(3)
driver.find_element_by_xpath('//*[@id="datepicker-1361-7562-title"]/strong').click()
问题是,我可以单击下拉菜单上的其他元素,但不能单击此按钮
运行代码时遇到的错误
in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="datepicker-1361-7562-title"]/strong"} (Session info: chrome=81.0.4044.122)
我一直在试图解决这个问题,但似乎无法确定我到底做错了什么,任何帮助都将不胜感激
切换到框架并单击日历后,第一部分“startDate”您可以使用以下选择器找到年份按钮
如果您希望单击“结束日期”部分,请更改
//div[@ng-model='']
的路径相关问题 更多 >
编程相关推荐