使用Selenium WebDriver从Jquery,日期选择器中选择一个日期
- 转到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");