gpt4 book ai didi

tinymce - 使用 watir-webdriver 自动化时如何处理 tinyMCE?

转载 作者:行者123 更新时间:2023-12-04 12:00:16 26 4
gpt4 key购买 nike

我正在评估 Watir-webdriver,以决定是否可以将它用于我的浏览器测试(主要来自 Watir),其中一个关键是能够与 TinyMCE WYSIWYG 编辑器进行交互,因为我的许多应用程序使用 TinyMCE。
我设法使以下解决方案起作用-

@browser = Watir::Browser.new(:firefox)
@browser.goto("http://tinymce.moxiecode.com/tryit/full.php")
autoit = WIN32OLE.new('AutoITX3.Control')
autoit.WinActivate('TinyMCE - TinyMCE - Full featured example')
@browser.frame(:index, 0).body.click
autoit.Send("^a") # CTRL + a to select all
autoit.Send("{DEL}")
autoit.Send("Some new text")

这种方法的缺点是,通过使用 autoit,我仍然依赖于 Windows,并且跨平台运行测试的能力是 webdriver 的吸引力之一。

我注意到一些特定于 webdriver 的解决方案,例如来自 this thread 的以下解决方案:
String tinyMCEFrame = "TextEntryFrameName" // Replace as necessary
this.getDriver().switchTo().frame(tinyMCEFrame);
String entryText = "Testing entry\r\n";
this.getDriver().findElement(By.id("tinymce")).sendKeys(entryText);
//Replace ID as necessary
this.getDriver().switchTo().window(this.getDriver().getWindowHandle());
try {
Thread.sleep(3000);
} catch (InterruptedException e) {

e.printStackTrace();
}

this.getDriver().findElement(By.partialLinkText("Done")).click();

看起来它可能跨平台工作,但我不知道是否可以从 Watir-webdriver 中访问相同的功能。我的问题是,有没有办法使用 watir-webdriver 写入、删除和提交到 TinyMCE,它不会强制依赖于特定支持的浏览器或操作系统?

最佳答案

目前,您需要进入并获取底层驱动程序实例。这在 TinyMCE 示例页面上对我有用

b = Watir::Browser.new
b.goto "http://tinymce.moxiecode.com/tryit/full.php"

d = b.driver
d.switch_to.frame "content_ifr"
d.switch_to.active_element.send_keys "hello world"

这实际上在 watir-webdriver 中没有很好地暴露出来,但我会解决这个问题。在下一个版本 (0.1.9) 之后,您应该可以简单地执行以下操作:
b.frame(:id => "content_ifr").send_keys "hello world"

关于tinymce - 使用 watir-webdriver 自动化时如何处理 tinyMCE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4664155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com