【发布时间】:2014-08-08 08:41:38
【问题描述】:
我是 selenium 的新手,正在尝试在 junit 框架中自动化 Web 应用程序。由于许多人在识别 Web 元素时遇到了一些问题,我也停留在两个提交按钮具有相同的 xpath 和 css 选择器的点上。
我能观察到的唯一区别是.. 在两个表单标签中,我可以看到 className 是不同的(第一个表单标签是"feature_space_checkbox",第二个表单标签是“auto_fs_steps_checkbox")
因为,我需要识别第二个提交按钮..所以我尝试识别第二个提交按钮,如下所示
driver.findElement(new ByChained(By.className("auto_fs_steps_checkbox"),By.xpath("//*[@id='edit_brochure_2863']/input[3]")));
当我尝试执行此操作时,我得到了错误
org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.chained({By.className: auto_fs_steps_checkbox,By.xpath: //*[@id='edit_brochure_2863']/input[3]})
哪位大神可以指正一下我的错误
为这个场景添加 DOM
<form action="/brochures/2865/feature_space_checked" class="feature_space_checkbox" id="edit_brochure_2865" method="post"><div style="margin:0;padding:0">
<input name="commit" type="submit" value="Submit">
</form>
第二个提交按钮是..
<form action="/brochures/2865/update_auto_fs_steps" class="auto_fs_steps_checkbox" id="edit_brochure_2865" method="post"><div style="margin:0;padding:0">
<input name="commit" type="submit" value="Submit">
</form>
【问题讨论】: