使用Selenium WebDriver从Jquery,日期选择器中选择一个日期 [英] Select a date from Jquery, date picker using selenium webdriver

查看:143
本文介绍了使用Selenium WebDriver从Jquery,日期选择器中选择一个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 转到Jquery的官方网站 https://jqueryui.com/datepicker/

即使它具有唯一的id ="datepicker",也不允许单击输入文本,但未找到错误元素.但是当我通过添加jquery日期选择器在本地运行时,它就像一个魅力.有人可以帮我解决不了吗!

It's not allow be to click on input text even it's have unique id="datepicker" getting an error element not found Exception but when i runs locally by adding jquery date picker it works likes a charm. can somebody help me can't able to figure it out!

2)通过使用此url,我可以选择任何内容,但不能与jquery官方站点一起使用,如上文所述 https://jqueryui.com/resources/demos/datepicker/default.html

2) By using this url i can select anything but it not works with jquery official site as i mentioned above https://jqueryui.com/resources/demos/datepicker/default.html

下面是我没有工作的实际代码

Below is my actual code that is not getting work

System.setProperty("webdriver.chrome.driver","C:\\ProgramFiles\\chromedriver.exe");

      driver=new ChromeDriver();
      driver.manage().window().maximize();
      driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
      driver.get("https://jqueryui.com/datepicker/");
      Thread.sleep(5000);
      driver.findElement(By.id("datepicker")).click();

推荐答案

带有id="datepicker"的元素在frame之内.因此,我们必须首先切换到预期的frame,然后找到该元素,然后按如下所示调用click()方法:

The element with id="datepicker" is within a frame. So we have to switch to the intended frame first, then locate the element and then call the click() method as follows:

System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("https://jqueryui.com/datepicker/");
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='demo-frame'][@src='/resources/demos/datepicker/default.html']")));
driver.findElement(By.id("datepicker")).click();
System.out.println("Datepicker Clicked");

这篇关于使用Selenium WebDriver从Jquery,日期选择器中选择一个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆