簡體   English   中英

Selenium Python send_keys 到代碼塊

[英]Selenium Python send_keys to a code block

我必須在代碼塊中插入一些 python 代碼。 這是代碼塊。

我試圖獲取塊並單擊它。 那個有效!

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

但是,當我嘗試使用 send_keys 時,出現了一些錯誤。

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

示例python代碼:

def hello:
   print("Hi")

手動地,當我將上述代碼添加到該代碼塊中時,結構如下所示。 DOM結構

如何解決?

這里的 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM