【问题标题】:Selecting the date from calendar从日历中选择日期
【发布时间】:2020-05-13 13:07:33
【问题描述】:

如何从日历中选择日期?

网站中有日历。选择日期的方法是单击任意日期并将鼠标指针拖动到所需日期,然后松开鼠标单击。

尝试了 ActionClass 但没有成功?

谁能帮帮我?

【问题讨论】:

  • 分享详情。错误,您的日历的 DOM 和您尝试过的代码 sn-p。
  • @Test public void selectDate() throws InterruptedException { System.setProperty("webdriver.chrome.driver", "C:\\Users\\A740493\\webautomation\\webauto\\src\\主\\资源\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("automationintesting.online/#/"); Thread.sleep(2000);
  • driver.findElement(By.xpath("//button[@id='next']")).click(); driver.findElement(By.xpath("//button[@id='next']")).click(); driver.findElement(By.xpath("//button[@id='next']")).click(); driver.findElement(By.xpath("//button[@id='next']")).click(); driver.findElement(By.xpath("//button[@id='closeModal']")).click();线程.sleep(5); driver.findElement(By.xpath("//button[text()= '预订这个房间']")).click(); System.out.println("点击按钮");
  • Thread.sleep(5); WebElement calendar = driver.findElement(By.xpath("//div[@class='rbc-month-row'][4]"));动作动作 = 新动作(驱动程序); act.dragAndDropBy(日历,628,1242).release().build().perform();日历.click();
  • 以上是我创建的全部代码。该代码包含应用程序 URL:automationintesting.online/# 我没有收到任何错误。测试用例成功通过。但这是一个错误的通行证

标签: selenium automation datepicker webautomation


【解决方案1】:

尝试更改act.dragAndDropBy(calendar,628,1242).release().build().perform();

act.dragAndDropBy(startDateWebElement,0,100).release().build().perform();

它将选择日历上的行。您也可以通过传递 startDate 和 endDate 定位器尝试使用以下方法:

WebElement startDate = driver.findElement(By.xpath("//a[text()='16']/parent::div"));
WebElement endDate = driver.findElement(By.xpath("//a[text()='22']/parent::div"));  

action.clickAndHold(startDate).moveToElement(endDate).click().release().build().perform();
action.dragAndDrop(startDate, endDate).build().perform();
action.clickAndHold(startDate).release(endDate).build().perform();

【讨论】:

    猜你喜欢
    • 2021-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-12
    • 2021-10-29
    • 2016-09-21
    • 1970-01-01
    相关资源
    最近更新 更多