无法使用Selenium WebDriver将Keys()发送到TinyMCE [英] Can't sendKeys() to TinyMCE with Selenium WebDriver

查看:123
本文介绍了无法使用Selenium WebDriver将Keys()发送到TinyMCE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Eclipse中使用Selenium WebDriver,并且试图将文本插入网页上的tinymce框中.这是我正在使用的代码.

I am using Selenium WebDriver in Eclipse and I am trying to insert text into a tinymce box on a web page. This is the code I am using.

//find tinymce iframe
editorFrame = driver.findElement(By.cssSelector(".col_right iframe"));

//switch to iframe
driver.switchTo().frame(editorFrame);
driver.findElement(By.className("mceContentBody")).sendKeys("YOOOO");
driver.switchTo().defaultContent();

光标在编辑器内部闪烁,但是未发送任何文本. 我也尝试过这种轻微的变化,但没有任何运气.

The cursor is blinking inside of the editor, however no text is sent. I have also tried this slight variation without any luck.

//find tinymce iframe
editorFrame = driver.findElement(By.cssSelector(".col_right iframe"));  

//switch to iframe
driver.switchTo().frame(editorFrame);
WebElement body = driver.findElement(By.className("mceContentBody"));
body.sendKeys("YOOOO");
driver.switchTo().defaultContent();

推荐答案

是的,正如Richard所说,这是 How使用selenium/webdriver 将文本输入tinceMCE编辑器.

Yes, as what Richard says, this is a duplicate of How to input text into tinceMCE editior using selenium/webdriver.

对于您的特定代码,我建议

For your specific code, I'd suggest

  • mceContentBody尝试其他定位器,例如使用By.cssSelector(".mceContentBody")By.cssSelector("body")等.

  • Try different locator for mceContentBody, e.g use By.cssSelector(".mceContentBody"), By.cssSelector("body"), etc.

在发送键之前先单击主体.

Click the body first before sending keys.

driver.findElement(By.tagName("body")).click().sendKeys("YOOOO");

  • 设置innerHTML
  • inputWebDriver.switchTo().frame("input-data_ifr");
    WebElement element = inputWebDriver.findElement(By.cssSelector("body"));
    (JavascriptExecutor)driver.executeScript("arguments[0].innerHTML = '<h1>Set text using innerHTML</h1>'", element);
    

    • 使用TinyMCE的本机API
    • // no need to switch iframe
      (JavascriptExecutor)driver.executeScript("tinyMCE.activeEditor.setContent('<h1>Native API text</h1> TinyMCE')");
      

      进一步阅读:使用Selenium测试所见即所得编辑器WebDriver

      这篇关于无法使用Selenium WebDriver将Keys()发送到TinyMCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆