硒 - 在网页中选择日期时问题
我正在尝试从网页中选择一些数据: https://indiawris.gov.in/wris/ #/地下水 在选择网页中的开始日期时,我面临问题。我已经尝试使用与此类似的代码相似的尝试,但是在这里它不起作用。
#code snippet tried for date picking earlier which is not working now
startdate_ele = driver.find_element_by_id('start_date_1')
startdate_ele.clear()
startdate = '2016/11/01' ## set the start date
end_date_ele = driver.find_element_by_id('end_date_1')
end_date_ele.clear()
endDate ='2017/07/31' ## set the end date for files to download
startdate_ele.send_keys(startdate)
time.sleep(5)
end_date_ele.send_keys(endDate)
以下是当前代码。
#functional code that does selection prior to the date picking
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import Select
path2 = r"F:\\chromedriver_win32\\chromedriver.exe"
driver = webdriver.Chrome(executable_path=path2)
driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get("https://indiawris.gov.in/wris/#/groundWater")
# try:
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@class='ng-star-inserted']")))
print('Switched successfully to iframe')
ele = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@class='views']//label[contains(.,'Basin')]//input")))
driver.execute_script("arguments[0].click();", ele)
print('Clicked on basin button')
sourceDrop = driver.find_element_by_xpath('//*[@id="applications"]/div[2]/div/groundwater-sidebar/div/div[2]')
sourceItems = sourceDrop.find_elements_by_class_name('ng-star-inserted')
print("length",len(sourceItems))
actionChains = ActionChains(driver)
select = Select(driver.find_element_by_xpath('//*[@id="applications"]/div[2]/div/groundwater-sidebar/div/div[2]/select'))
select.select_by_visible_text('CGWB')
select = Select(driver.find_element_by_xpath('//*[@id="applications"]/div[2]/div/groundwater-sidebar/div/div[3]/select'))
select.select_by_visible_text('yyyyMMdd')
startdate_ele = driver.find_element_by_xpath('//*[@id="applications"]/div[2]/div/groundwater-sidebar/div/div[4]/datepicker/div/input')
startdate_ele.clear()
startdate = '03-January-2021' ## set the start date
end_date_ele = driver.find_element_by_id('end_date_1')
end_date_ele.clear()
endDate ='2017/07/31' ## set the end date for files to download
startdate_ele.send_keys(startdate)
time.sleep(5)
end_date_ele.send_keys(endDate)
有人可以帮助我从该门户网站挑选日期进行选择。
I am trying to select some data from webpage: https://indiawris.gov.in/wris/#/groundWater
I am facing problem while picking the start and end dates in the webpage. I have made an attempt using a code similar to this earlier, but here it did not work.
#code snippet tried for date picking earlier which is not working now
startdate_ele = driver.find_element_by_id('start_date_1')
startdate_ele.clear()
startdate = '2016/11/01' ## set the start date
end_date_ele = driver.find_element_by_id('end_date_1')
end_date_ele.clear()
endDate ='2017/07/31' ## set the end date for files to download
startdate_ele.send_keys(startdate)
time.sleep(5)
end_date_ele.send_keys(endDate)
Following is the current code.
#functional code that does selection prior to the date picking
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import Select
path2 = r"F:\\chromedriver_win32\\chromedriver.exe"
driver = webdriver.Chrome(executable_path=path2)
driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get("https://indiawris.gov.in/wris/#/groundWater")
# try:
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@class='ng-star-inserted']")))
print('Switched successfully to iframe')
ele = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@class='views']//label[contains(.,'Basin')]//input")))
driver.execute_script("arguments[0].click();", ele)
print('Clicked on basin button')
sourceDrop = driver.find_element_by_xpath('//*[@id="applications"]/div[2]/div/groundwater-sidebar/div/div[2]')
sourceItems = sourceDrop.find_elements_by_class_name('ng-star-inserted')
print("length",len(sourceItems))
actionChains = ActionChains(driver)
select = Select(driver.find_element_by_xpath('//*[@id="applications"]/div[2]/div/groundwater-sidebar/div/div[2]/select'))
select.select_by_visible_text('CGWB')
select = Select(driver.find_element_by_xpath('//*[@id="applications"]/div[2]/div/groundwater-sidebar/div/div[3]/select'))
select.select_by_visible_text('yyyyMMdd')
startdate_ele = driver.find_element_by_xpath('//*[@id="applications"]/div[2]/div/groundwater-sidebar/div/div[4]/datepicker/div/input')
startdate_ele.clear()
startdate = '03-January-2021' ## set the start date
end_date_ele = driver.find_element_by_id('end_date_1')
end_date_ele.clear()
endDate ='2017/07/31' ## set the end date for files to download
startdate_ele.send_keys(startdate)
time.sleep(5)
end_date_ele.send_keys(endDate)
can some one help me in picking the dates from this portal to do the selection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码当前有几个问题。
There are several issues currently wrong with your code.
对于以下几个月,代码将有效地导航WRT年,我们需要添加更多逻辑。
For selecting Months below code will work to navigate w.r.t year we need to add more logic.