Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Selenium中单击并打开页面上的日历?_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Python 如何在Selenium中单击并打开页面上的日历?

Python 如何在Selenium中单击并打开页面上的日历?,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我正试图通过单击下面的按钮来选择日期。但是,当我尝试查找元素并单击时,没有出现错误,但页面上的日历没有打开 我无法找出我在这里做错了什么,或者有没有办法直接输入日期 <div class="was-bold-text">To</div> <div class="was-date-container was-light-text" data-displaydate

我正试图通过单击下面的按钮来选择日期。但是,当我尝试查找
元素
并单击
时,没有出现错误,但页面上的日历没有打开

我无法找出我在这里做错了什么,或者有没有办法直接输入日期


                <div class="was-bold-text">To</div>
                <div class="was-date-container was-light-text" data-displaydate="End Date">
    <input name="" value="" id="was-returns-reconciliation-report-end-date" type="date" class="was-form-control was-input-date" data-defaultdate="" data-mindate="" data-maxdate="today" data-placeholder="End Date" max="2020-02-12" min="2020-02-04">
    
</div>

选择日期或打开日历并单击所需日期的方法是什么?

不久前也有同样的问题,通过javascript设置日期选择器值来解决。这不是你正在寻找的点击,但可能会解决你在C中的问题。是这样的:

((IJavaScriptExecutor)driver).ExecuteScript("document.getElementById('was-returns-reconciliation-report-end-date').value='2020-01-05'");
因此,在python中,我想可能会出现以下语法错误:

driver.execute_script("document.getElementById('was-returns-reconciliation-report-end-date').value = '2020-01-05'")

您不必单击日期选择器,因为它是一个本机输入元素,不像datepicker或datetimepicker那样是插件。但是你可以用下面的方法来设置值

datepicker = driver.find_element_by_id('was-returns-reconciliation-report-end-date')
datepicker.clear() # clear values if any.
datepicker.send_keys("02/12/2020")

我想这对你有用。

对我没用。它没有抛出错误,但日期没有更改,当我单击“下一步”按钮时,它显示日期不能为空。不适用于所有日期选择器,也可能是日期格式,将其编辑为与dpicker的格式匹配。如果其他解决方案不起作用,我现在已经找到了一个有效的解决方案。i、 e.查找元素并向元素发送键。
datepicker = driver.find_element_by_id('was-returns-reconciliation-report-end-date')
datepicker.clear() # clear values if any.
datepicker.send_keys("02/12/2020")