【问题标题】:Unable to locate element: {"method":"id","selector":"sysPublishDateDate"}无法定位元素:{"method":"id","selector":"sysPublishDateDate"}
【发布时间】:2013-08-11 03:25:14
【问题描述】:

我尝试调用文本框。但我收到以下错误:无法找到元素:{"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);

在此代码中,它只输入值。我还尝试为此识别 Frames 和 iframe,但那里没有任何阻塞。为了找到解决方案,我一直坚持这一点。

【问题讨论】:

    标签: java xpath selenium-webdriver


    【解决方案1】:

    试试这个

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 2017-12-25
      • 2019-11-25
      • 1970-01-01
      • 1970-01-01
      • 2020-03-18
      相关资源
      最近更新 更多