[英]Locating CK Editor and Sending text to it in Selenium Webdriver
嗨,我正在尝试通过 Selenium Webdriver 代码(Java)为我的项目找到 CK 编辑器。 但是每当我尝试使用 SendKeys() 方法时,它都对我不起作用。 下面是CK编辑器和HTML代码的截图。
下面是代码,
if(driver.findElement(By.cssSelector("iframe#scayt_8")).isEnabled())
{
WebElement iframe = driver.findElement(By.cssSelector("iframe#scayt_8"));
System.out.println("Frame Enabled");
if(driver.findElement(By.xpath("//iframe[@id = 'scayt_8']")).isDisplayed())
{
System.out.println("Frame Displayed");
driver.switchTo().frame(iframe);
iframe.clear();
System.out.println("Clicking frame");
iframe.click();
iframe.sendKeys("Hello!!");
}
}
请帮助我找到 CK 编辑器并向其发送文本。
您可能需要切换到内联框架才能找到它。
WebElement editorFrame = driver.findElement(By.id("scayt_8"));
driver.switchTo().frame(editorFrame);
WebElement body = driver.findElement(By.tagName("body"));
body.clear();
body.sendKeys("some text");
我们在 Selenium WebDriver In Practice 一书的第 3 章中提供了与编辑器合作的技巧。
我认为 iframe 是基于 cssSelector 进行搜索的,但我认为它应该基于 id? 这是 scayt_8。 您可以尝试使用以下代码来获取 iframe 而不是 cssSelector:
driver.FindElement(By.TagName("iframe"))
切换到 iframe 后,尝试通过 iframe 中的段落标记名称定位 webelement,如下所示:-
WebElement body=driver.findElement(By.tagName("p"));
然后尝试使用此 webelement 发送密钥:
body.sendKeys("Hello!!");
WebElement iframe = driver.findElement(By.tagName("iframe")); driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Hello, ckeditor!");;
这将帮助您在 CKeditor 中发送文本。 尝试这个。 它会工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.