[英]Selenium Python send_keys to a code block
I have to insert some python code into a code block.我必须在代码块中插入一些 python 代码。
I tried to fetch the block and click on it.我试图获取块并单击它。 That works!
那个有效!
code_box = driver.find_element_by_xpath('//*[@id="prog-div-py3"]/div/div[6]')
code_box.click()
But, when I tried to send_keys to it, got some errors.但是,当我尝试使用 send_keys 时,出现了一些错误。
selenium.common.exceptions.ElementNotInteractableException: Message: element
not interactable
Sample python code:示例python代码:
def hello:
print("Hi")
Manually, when I added the above code into that code block, the structure looks like this.手动地,当我将上述代码添加到该代码块中时,结构如下所示。
How to resolve?如何解决?
The Webelement here is CodeMirror.这里的 Webelement 是 CodeMirror。 The following code worked for me, pls try using it:
以下代码对我有用,请尝试使用它:
WebElement codeMirror = driver.findElement(By.className("CodeMirror"));
WebElement codeLine = codeMirror.findElements(By.className("CodeMirror-line")).get(0);
codeLine.click();
WebElement txtbx = codeMirror.findElement(By.cssSelector("textarea"));
txtbx.sendKeys(text);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.