将文本发送到 ckeditor 后,它无法识别下一个元素(selenium)
After sending text to ckeditor it does not recognize next element (selenium)
我通过这些命令
成功将文本发送到 ckeditor
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Automation Description");
问题
文本 "Automation Description" 已成功传递给 ckeditor
。
但。它没有找到下一个元素
显示以下错误
no such element: Unable to locate element:
{"method":"xpath","selector":".//*[@id='select2-state_name-container']"}
当我添加区块评论时
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Automation Description");
定位到下一个元素成功
帮我添加一个命令,这样我就可以在向 ckeditor 发送文本后定位下一个元素。谢谢
这是一个屏幕截图:
我相信这与您的 switch frame 语句有关,
driver.switchTo().frame()
尝试在输入文本后切换回0索引框或默认索引框:
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Automation Description");
driver.switchTo().frame(0); //To go back to main frame
//continue
或者更好的是找到主框架的选择器 window 并切换到它,但我认为 0 应该适用于你的情况
希望对您有所帮助
正如我看到您的代码,您将首先切换框架,然后找到 ckeditor 并设置值。但是你没有切换回默认内容来找到下一个元素,这就是为什么 selenium 将定位器搜索到已经切换的框架中,而元素实际上不存在,所以你应该尝试在找到元素之前切换回来,如下所示:-
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Automation Description");
//Now switch back first to default
driver.switchTo().defaultContent();
//Now you can go to find next element
希望对您有所帮助...:)
我通过这些命令
成功将文本发送到ckeditor
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Automation Description");
问题
文本 "Automation Description" 已成功传递给 ckeditor
。
但。它没有找到下一个元素
显示以下错误
no such element: Unable to locate element: {"method":"xpath","selector":".//*[@id='select2-state_name-container']"}
当我添加区块评论时
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Automation Description");
定位到下一个元素成功
帮我添加一个命令,这样我就可以在向 ckeditor 发送文本后定位下一个元素。谢谢
这是一个屏幕截图:
我相信这与您的 switch frame 语句有关,
driver.switchTo().frame()
尝试在输入文本后切换回0索引框或默认索引框:
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Automation Description");
driver.switchTo().frame(0); //To go back to main frame
//continue
或者更好的是找到主框架的选择器 window 并切换到它,但我认为 0 应该适用于你的情况
希望对您有所帮助
正如我看到您的代码,您将首先切换框架,然后找到 ckeditor 并设置值。但是你没有切换回默认内容来找到下一个元素,这就是为什么 selenium 将定位器搜索到已经切换的框架中,而元素实际上不存在,所以你应该尝试在找到元素之前切换回来,如下所示:-
WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);
WebElement tinymce = driver.findElement(By.tagName("body"));
tinymce.clear();
tinymce.sendKeys("Automation Description");
//Now switch back first to default
driver.switchTo().defaultContent();
//Now you can go to find next element
希望对您有所帮助...:)