gpt4 book ai didi

javascript - 如何使用 java selenium 将 sendKeys 用于 ckeditor 文本区域

转载 作者:搜寻专家 更新时间:2023-11-01 03:18:30 26 4
gpt4 key购买 nike

如何将键发送到 java selenium 中的 Reach 文本区域。

这是包含 Iframe 的 HTML 代码:

<div class="col-sm-11">
<textarea class="ckeditor ng-untouched ng-empty ng-invalid ng-invalid-required ng-dirty ng-valid-parse" ng-class="{true:'validation-error'}[submitted]" placeholder="Enter text ..." ck-editor="" ng-model="NewTicket.Message" name="Message" style="visibility: hidden; display: none;" aria-invalid="true"/>
<div id="cke_Message" class="cke_1 cke cke_reset cke_chrome cke_editor_Message cke_ltr cke_browser_gecko" lang="en" aria-labelledby="cke_Message_arialbl" role="application" dir="ltr">
<span id="cke_Message_arialbl" class="cke_voice_label">Rich Text Editor, Message</span>
<div class="cke_inner cke_reset" role="presentation">
<span id="cke_1_top" class="cke_top cke_reset_all" style="height: auto; -moz-user-select: none;" role="presentation">
<div id="cke_1_contents" class="cke_contents cke_reset" role="presentation" style="height: 200px;">
<span id="cke_50" class="cke_voice_label">Press ALT 0 for help</span>
<iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" src="" style="width: 100%; height: 100%;" title="Rich Text Editor, Message" aria-describedby="cke_50" tabindex="0" allowtransparency="true"/>
</div>
</div>
</div>
<span class="ng-binding ng-hide" style="color:red" ng-show="newTicketForm.Message.$invalid && submitted" aria-hidden="true">Content is required</span>
</div>

我尝试使用以下使用 Iframe 类名的方法,但无法向其发送数据。这是 Selenium 代码

for (String handle002 : driver.getWindowHandles()) 
{
driver.switchTo().window(handle002);
Thread.sleep(500);
for (String handle001 : driver.getWindowHandles())
{
driver.switchTo().window(handle001);
Thread.sleep(500);
driver.switchTo().frame(driver.findElement(By.className("cke_wysiwyg_frame cke_reset")));
driver.switchTo().defaultContent();
WebElement body=driver.findElement(By.className("cke_wysiwyg_frame cke_reset"));
body.sendKeys("Test");
driver.switchTo().defaultContent();
}
}

enter image description here

最佳答案

在看到您提供的 HTML 后我得到了解决方案,您应该尝试使用 WebDriverWait 如下:-

WebDriverWait wait = new WebDriverWait(driver, 10);

wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe.cke_wysiwyg_frame.cke_reset")));

WebElement body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.tagName("body")));
body.sendKeys("Test String");

//Now after entering text into texteditor switch back to default content
driver.switchTo().defaultContent();

关于javascript - 如何使用 java selenium 将 sendKeys 用于 ckeditor 文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39284833/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com