<h6>
<a href="blah">top</a>
<form method="post" name="prod" action="blah.jsp>
<input type="hidden" name="a" value="asdfsd">Jump to product:
<input type="text" name="p" size="25">
<a href="#" onclick="document.forms['prod'].submit()">GO</a>
</form>
<form method="get" name="catgy" action="cato.jsp">
<input type="hidden" name="a" value="asdfs3">Jump to category:
<input type="text" name="c" size="25">
<a href="#" onclick="document.forms['category'].submit()">GO</a>
</form>
</h6>
这两者都不返回元素
WebElement form = driver.findElement(By.xpath("//body/h6/form[2]"));
也不是
WebElement form = driver.findElement(By.name("catgy"));
您能帮忙获取表单元素吗?
答案 0 :(得分:1)
试试这个
driver.findElement(By.cssSelector("form[name='catgy']"));