繁体   English   中英

xpath可用于硒记录,但不能在Eclipse中运行

[英]xpath works in selenium recording, but does not run in Eclipse

我试图在以前在Selenium中记录的Eclipse中运行测试。 我能够通过使用XPath使其在Selenium中运行。 但是,在Eclipse中,我收到了NoSuchElement错误。 我试图单击页面上的一个选项卡,问题是这些选项卡未作为按钮列出,但实际上在表中。 这是我现在已有的行。

driver.findElement(By.xpath("(//div[@onclick=\"parent.frames.contentFrame.location='/messaging/maintfList.jsp?clearUIPath=true&uiPathLabel=Forms'\"])")).click();

这是检查元素时显示的内容。 所有选项卡均列为正常菜单,唯一的区别是路径标签。

div class="menu-normal" onclick="parent.frames.contentFrame.location='/messaging/maintfList.jsp?clearUIPath=true&uiPathLabel=Forms'"

我会尝试

driver.findElement(By.cssSelector("div[onclick='parent.frames.contentFrame.location='/messaging/maintfList.jsp?clearUIPath=true&uiPathLabel=Forms']")).click();

在Java中转义任何需要它的东西。

xpath是一种发现事物的非常低效的方法,几乎​​总是有一种更好的方法。 在这种情况下,CssSelector可以找到您想要的东西。

编辑:我看过Java文档,请尝试使用此行

driver.findElement(By.cssSelector("div[onclick=\"parent.frames.contentFrame.location='/messaging/maintfList.jsp?clearUIPath=true&uiPathLabel=Forms'\"]")).click();

您也可以尝试以下方法:

driver.findElement(By.xpath("//div[@class='menu-normal'][2]")).click();

//这里[2]是页面上正常菜单的位置号。 让我们假设有4个选项卡具有相同的类,并且您想单击第二个选项卡,则可以使用上面的代码。

如果没有帮助,请分享您的HTML代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM