2012-08-27 13 views
5

Sto usando WebDriver in Java con Firefox 14.utilizzando Selenio WebDriver con CKEditor in Firefox 14

Il mio problema è che non riesco a ottenere WebDriver a giocare bene con CKEditor. Ho cercato soluzioni, ma sono stato in grado di ottenere qualsiasi lavoro sia in Firefox 13 o 14. Queste sono le soluzioni che ho provato:

  1. I normali Sendkeys interction

    textArea.sendKeys(); 
    

    o

    textArea.click(); 
    textArea.sendKeys(); 
    

    Risultato: Questo codice non produrrebbe alcun testo nella CKEditor

  2. Il codice da Selenium issue 3890

    d.get("http://ckeditor.com/demo"); 
    WebElement iframe = d.findElement(By.tagName("iframe")); 
    d.switchTo().frame(iframe); 
    WebElement tinymce = d.findElement(By.tagName("body")); 
    tinymce.clear(); 
    tinymce.sendKeys("Hello, ckeditor!"); 
    

    Risultato: Questo codice andrà al sito e chiaro l'editor, ma non metterà in alcun testo nell'istanza CKEditor.

  3. AdvancedUserInteractions - ad es. Azioni() in più varianti

    textArea.click(); 
    new Actions(driver).sendKeys("Hello, ckeditor!").build().perform(); 
    

    e

    new Actions(driver).sendKeys(textArea, "Hello, ckeditor!").build().perform(); 
    

    e

    new Actions(driver).click(textArea).sendKeys("Hello, ckeditor!").build().perform(); 
    

    risultati: Questi non produrranno alcun testo nella CKEditor

  4. commutazione iframe (come da Issue 3890 sopra) e usando Advan cedUserInteractions

    codice simile a:

    driver.switchTo().frame(iframe); 
    textArea.click(); 
    new Actions(driver).sendKeys("Hello, ckeditor!").build().perform(); 
    

    Risultato: Genera errore "c.value è indefinito"

  5. Usando il Javascript e l'API CKEditor

    JavascriptExecutor js = (JavascriptExecutor) d; 
    System.out.println("[debug] Set Text: " + setText); 
    js.executeScript("CKEDITOR.instances.editor1.setData('<p> "+ setText +"</p>');"); 
    

    Risultato: esclude il carattere '/' quando "org.apache.commons.lang.StringEscapeUtils.escapeHtml" è/non viene utilizzato per convertire "setText" in voci HTML. Questa soluzione genera anche "ERRORE : null" su stringhe di grandi dimensioni.

Qualche idea su cose che non ho provato? Correzioni per cose che ho provato? Qualche altro suggerimento?

Grazie!

risposta

3

A volte le aree di testo vengono gestite come Iframe in cui è necessario passare a tale frame ed eseguire il comando JS per digitare su di esso.

final WebDriver frame = driver.switchTo().frame(findElement(By.id("locator")); //any locator 
    ((JavascriptExecutor) driver).executeScript("document.body.innerHTML='" + TestValueThatYouWantToType + "'"); 
    driver.switchTo().defaultContent(); 
0

Basta aggiungere la dichiarazione di attesa dopo tinymce.clear(); e funzionerà correttamente.

Problemi correlati