从硒中的JavaScriptExecutor选择日历日期

我正在尝试从Selenium中的JavaScriptExecutor选择日历日期,但未选择日期,也没有控制台为此提供任何错误。我无法理解其背后的原因。谁能帮忙。下面是我编写的硒代码。

package SeleniumSessions;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class SelectCalendarByJS {

    public static void main(String[] args) {


        System.setProperty("webdriver.chrome.driver","F:\\Drivers\\chromedriver_win32\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();

        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();

        driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        driver.get("https://www.makemytrip.com/");

        //WebElement date = driver.findElement(By.xpath("//div[@class = 'fsw_inputBox dates inactiveWidget ']"));

        WebElement date = driver.findElement(By.xpath("//input[@id = 'departure']"));

        String dateVal = "Friday, 19 Jun 2020";

        selectDateByJS(driver, date, dateVal);

        //driver.quit();

    }

    public static void selectDateByJS(WebDriver driver , WebElement element , String dateVal) {
        JavascriptExecutor js = ((JavascriptExecutor)driver);
        js.executeScript("arguments[0].setAttribute('value','"+dateVal+"');", element);

    }
}

下面是我选择的属性的HTML DOM。

<input data-cy="departure" id="departure" type="text" class="fsw_inputField font20" readonly="" value="Friday, 19 Jun 2020">
评论