【问题标题】:Unable to set value to DatePicker-Selenium WebDriver using JavascriptExecutor [duplicate]无法使用 JavascriptExecutor 将值设置为 DatePicker-Selenium WebDriver [重复]
【发布时间】:2019-02-08 15:48:54
【问题描述】:

无法使用 JavascriptExecutor 为 DatePicker-Selenium WebDriver 设置值

public class CopyOfDatePicker {
public static void main(String[] args) throws InterruptedException {
    System.setProperty("webdriver.chrome.driver","D://Drivers//chromedriver_win32//chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.spicejet.com/");
    Thread.sleep(6000);
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("document.getElementById('ctl00_mainContent_txt_Fromdate').value='11-02-2019'");
}

}

【问题讨论】:

    标签: selenium-webdriver


    【解决方案1】:

    我建议您不要注入 javascript,因为这确实是一种不好的做法。您可能会错过一些潜在的问题,因为它不会调用任何关联的事件。

    查看这篇解释如何自动化日期选择器的帖子 - 还有一个演示来展示它是如何工作的。

    http://www.testautomationguru.com/selenium-webdriver-automating-custom-controls-datepicker/

    【讨论】:

      猜你喜欢
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      • 2022-07-25
      • 1970-01-01
      • 2016-05-29
      • 2018-02-01
      • 1970-01-01
      • 2016-02-11
      相关资源
      最近更新 更多