Selenium Python将_键发送到代码块

2024-06-25 23:32:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须在代码块中插入一些python代码。This is the code block.

我试着把积木取出来,然后点击它。真管用

code_box = driver.find_element_by_xpath('//*[@id="prog-div-py3"]/div/div[6]')
code_box.click()

但是,当我试图向它发送密钥时,出现了一些错误

selenium.common.exceptions.ElementNotInteractableException: Message: element 
not interactable

python代码示例:

def hello:
   print("Hi")

手动地,当我将上述代码添加到该代码块中时,结构如下所示。DOM structure

如何解决


Tags: 代码divboxidbydriverpy3密钥
1条回答
网友
1楼 · 发布于 2024-06-25 23:32:48

这里的Webelement是CodeMirror。以下代码适用于我,请尝试使用它:

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

相关问题 更多 >