如何在Python中使用Selenium编辑CodeMirror? [英] How do I edit CodeMirror with Selenium in Python?

查看:243
本文介绍了如何在Python中使用Selenium编辑CodeMirror?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次尝试在网页上的CodeMirror中插入文本时,我都会不断收到以下错误消息。有人知道如何用硒成功地编辑codemirror吗?

I keep getting the error message below every time I try to insert text into CodeMirror on my webpage. Does anyone know how to successfully edit codemirror with selenium?

WebDriverException: Message: unknown error: Cannot read property 'setValue' of undefined

这是我的Selenium-Python代码

This is my Selenium-Python code

def click_component_script_editor(self):
   driver = self.driver
   line18Edit = self.driver.find_element(By.XPATH, "//html//div[@class='CodeMirror-line']//div[18]/pre[1]")      
   driver.execute_script("arguments[0].CodeMirror.setValue(arguments[1]);",
                   line18Edit,
                   "foo.bar")


推荐答案

找出答案,我不得不使用actionChains而不是常规的旧send_keys。

Figured out the answer to this one, I had to use actionChains instead of just regular old send_keys.

codeMirror = self.driver.find_element(".CodeMirror")
action_chains.click(codeMirror).perform()
action_chains.send_keys("Hello World").perform()

这篇关于如何在Python中使用Selenium编辑CodeMirror?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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