我尝试调用文本框。但我收到以下错误:无法找到元素:{"method":"id","selector":"sysPublishDateDate"}
。
我在这里附上我的代码:
try{
WebElement title = driver.findElement(By.xpath("//div[@id='widget_title']//input[@id='title']"));
title.sendKeys("Automation");
WebElement browse = driver.findElement(By.xpath("//div[@id='listingThumbnail']//span[@id='dijit_form_Button_14']"));
browse.click();
driver.manage().timeouts().implicitlyWait(150,TimeUnit.SECONDS);
try{
List<WebElement> sidemenu = driver.findElements(By.xpath("//*[@id='dijit_layout_ContentPane_6']"));
for(WebElement drop:sidemenu){
System.out.println(drop.getText());
}
}catch(Exception e){
}
WebElement file = driver.findElement(By.xpath("//*[@id='dijit_layout_ContentPane_6']//div[5]/div[@class='dijitTreeRow']/img"));
file.click();
driver.manage().timeouts().implicitlyWait(150,TimeUnit.SECONDS);
WebElement thumbnails = driver.findElement(By.xpath("//*[@id='dotcms_dijit_FileBrowserDialog_2-tree-treeNode-3bc7e461-117f-4f0c-96fe-8edb24ec6cde']/div[1]"));
thumbnails.click();
driver.manage().timeouts().implicitlyWait(150,TimeUnit.SECONDS);
WebElement image = driver.findElement(By.xpath("//*[@id='file-5a88cc64-dd56-4d40-8778-8df7fb2f233d0']/a/img"));
image.click();
driver.manage().timeouts().implicitlyWait(150, TimeUnit.SECONDS);
driver.switchTo().defaultContent();
WebDriver myFrame= driver.switchTo().frame(driver.findElements(By.tagName("iframe")).get(0));
WebElement summary = myFrame.findElement(By.xpath("//*[@id='tinymce']"));
summary.sendKeys("Testing DotCMS");
//WebElement story = driver.findElement(By.xpath("//table[@id='story_tbl']//td[@class='mceIframeContainer mceFirst mceLast']/iframe"));
try{
driver.switchTo().defaultContent();
WebDriver myframe = driver.switchTo().frame(driver.findElement(By.xpath("//*[@id='story_ifr']")));
WebElement story = myframe.findElement(By.xpath("//*[@id='tinymce']"));
story.sendKeys("Testing DotCMS Automation");
}catch (Exception e){
System.out.println("iframe not found");
}
}catch (Exception e){
}
driver.manage().timeouts().implicitlyWait(150, TimeUnit.SECONDS);
WebElement dateselection = driver.findElement(By.id("sysPublishDateDate"));
dateselection.clear();
dateselection.sendKeys("8/7/2013",Keys.ENTER);
我在这行中出错。
WebElement dateselection = driver.findElement(By.id("sysPublishDateDate")); dateselection.clear(); dateselection.sendKeys("8/7/2013",Keys.ENTER);
在此代码中,只需输入值。我也尝试为此确定框架和iframe,但没有任何障碍物在那里。我因为寻找解决方案而陷入困境。
最佳答案
尝试这个
WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("sysPublishDateDate")));
要么
wait.until(ExpectedConditions.elementToBeClickable(By.id("sysPublishDateDate")));
然后使用
WebElement dateselection = driver.findElement(By.id("sysPublishDateDate"));
dateselection.clear();
dateselection.sendKeys("8/7/2013",Keys.ENTER);