在Selenium中与CKEditor进行交互 - Python

时间:2018-04-01 22:44:41

标签: python selenium ckeditor wysiwyg

我目前正致力于通过我用于工作的网站自动化电子邮件生成器。目前,我主要使用硒,因为我无法获得selenium与页面上的ckeditor进行交互。到目前为止,我已经尝试过......

切换到iframe,如other questions中所述:

Input_Frame = browser.find_element_by_tag_name('iframe')
browser.switch_to_frame(Input_frame)
Input_Element = browser.find_element_by_xpath("//iframe[@class='cke_wysiwyg_frame cke_reset']")
Input_Element.send_keys('Hello')

我也使用了几个xpath变体...... 我也尝试过css选择器:

Input_Frame = browser.find_element_by_css_selector("iframe[class='cke_wysiwyg_frame cke_reset']")
Input_Frame = browser.find_element_by_css_selector("iframe[title='Rich Text Editor, CKeditorEmail']")

以及索引:

browser.switch_to_frame(0)
browser.switch_to_frame(1)

在上述所有情况下,selenium无法找到元素/框架,因此我无法实际输入任何文本。

我最终试图摆​​弄this tutorial然而它有点过头了,我真的无法获得很多结果。我确实找到了进入CKEDITOR.instances [' CKeditorEmail']。setData(' Hello World!');进入Firefox的控制台后,对显示的文本进行了更改。

如果有人可以提供指示或指出解决方案,我将非常感激。其余的自动化程序或多或少都已完成 - 这是我的第一个大项目之一,而且我已经将这一步带走了多长时间。

此外,如果有人想在site's html处达到高峰。

提前致谢!

1 个答案:

答案 0 :(得分:0)

尝试一下,它对我有用,如果您需要更多信息,可以在这里找到文档。 https://yizeng.me/2014/01/31/test-wysiwyg-editors-using-selenium-webdriver/

frame = driver.find_element(By.CLASS_NAME, 'cke_wysiwyg_frame')
driver.switch_to.frame(frame)
body = self.driver.find_element(By.TAG_NAME, 'body')
body.send_keys('tester')