我试过调用文本框。但我收到以下错误:无法找到元素:{"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,但没有任何东西阻挡。为了找到解决方案,我被困在这里。
答案 0 :(得分:0)
试试这个
WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("sysPublishDateDate")));
OR
wait.until(ExpectedConditions.elementToBeClickable(By.id("sysPublishDateDate")));
然后使用
WebElement dateselection = driver.findElement(By.id("sysPublishDateDate"));
dateselection.clear();
dateselection.sendKeys("8/7/2013",Keys.ENTER);