【发布时间】:2021-09-15 23:12:33
【问题描述】:
我正在尝试学习网页中的拖放功能 Link Section Books 在 iframe 中。 但我无法访问我遇到错误的 iframe
没有这样的元素:无法找到元素:
以下是我尝试过的 Xpath
// WebElement frame =driver.findElement(By.xpath("//div[@id='root']//iframe[@class='st-preview-body']"));
// WebElement frame =driver.findElement(By.tagName("iframe"));
WebElement frame =driver.findElement(By.xpath("//iframe[@src='https://snippet.webixcode.com/snippet.html?0.0.3']"));
driver.switchTo().frame(frame);
我也尝试使用 by.id 以及使用 id 和类名的 xpath
我会犯什么错误?据我所知,只有一个 iframe 存在
拖放代码。这行得通吗?
WebElement fromdrag=driver.findElement(By.xpath("//span[@class='dhx_tree-list-item__text'][normalize-space()='Lawrence Block']"));
WebElement todrop=driver.findElement(By.id("treeTarget"));
Actions act=new Actions(driver);
act.dragAndDrop(fromdrag, todrop).build().perform();
【问题讨论】:
-
嗨@pamdhu 感谢您的评论。我已经进入框架接下来我想做拖放,下面是我的一段代码''''' WebElement ele1 = driver.findElement(By.xpath("//li[@class='dhx_tree-list__item dhx_tree -list-item']//span[@class='dhx_tree-list-item__text'][normalize-space()='Lawrence Block']")); System.out.println(ele1.getText());动作动作=新动作(驱动程序); act.dragAndDropBy(ele1, 448,37).build().perform();我得到 NowindowException 。无法继续拖放。
-
该操作运行良好,对我来说没有任何错误。请参阅此链接 - darganddrop。并检查
NoteThe pixels values change with screen resolution and browser size. This method is hence not reliable and not widely used.
标签: selenium iframe drag-and-drop