How do I edit CodeMirror with Selenium in Python?

点点圈 提交于 2020-01-02 07:42:11

问题


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

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")

回答1:


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()


来源:https://stackoverflow.com/questions/48956036/how-do-i-edit-codemirror-with-selenium-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!