所有
我们正在尝试自动化日期选择流程以供参考 Click here! 。请参考出生日期和预约日期字段。我们选择日期的方式是不同的。我无法知道如何选择两个字段的日期。你能帮我吗?
我已经尽了最大努力,除了日期字段
之外,还使用了以下代码Python版本:2.7 硒3.8.0 Chrome:48X
import selenium
import sys
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
#profile = webdriver.FirefoxProfile()
#profile.accept_untrusted_certs = True
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('https://reentryvisa.inis.gov.ie/website/INISOA/IOA.nsf/AppointmentSelection?OpenForm');
wait = WebDriverWait(driver, 10)
driver.find_element_by_id('btCom').click()
username = driver.find_element_by_id('GivenName')
username.send_keys("First name here ")
username = driver.find_element_by_id('Surname')
username.send_keys("Surname here")
username = driver.find_element_by_id('DOB')
username.click()
ActionChains(driver).move_to_element(username).click().send_keys('01/01/2011').perform()
username = driver.find_element_by_id('Appdate')
username.send_keys("12345")
我试着看到html的id名称等,但我发现任何特定的年份日期或月份。我得到的只是代码
<script src="/website/INISOA/IOA.nsf/bootstrap-datepicker.js"></script>
<link href="/website/INISOA/IOA.nsf/datepicker3.css" rel="stylesheet">
<div class="form-group">
<label class="control-label col-sm-3 col-md-3 col-lg-2" for="DOB">* Date of Birth:</label>
<div class="col-sm-3 col-md-3 col-lg-3">
<div class="input-group date dobdate">
<input name="DOB" value="" id="DOB" class="form-control readonlywhite" placeholder="Date of birth" readonly>
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>
</div>
请帮我显示选择两个字段中的日期(出生日期和约会日期)
答案 0 :(得分:0)
出生日期:
dob = driver.find_element_by_id('DOB')
driver.execute_script("arguments[0].value = arguments[1]", dob, '01/01/2011')
预约日期:
appdate = driver.find_element_by_id('Appdate')
driver.execute_script("arguments[0].value = arguments[1]", appdate, '12/12/2017')
答案 1 :(得分:0)
日期/月/年弹出窗口的html不在“DOB输入”下。您可以使用以下选择器选择弹出窗口
datePopup = driver.find_element_by_class('datepicker-days')
monthPopup = driver.find_element_by_class('datepicker-month')
yearPopup = driver.find_element_by_class('datepicker-years')