2015-08-28 27 views
0
<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")); 

你能幫獲取表單元素?

回答

1

試試這個

driver.findElement(By.cssSelector("form[name='catgy']")); 
+0

認爲應該有工作,但事實並非如此。不知道什麼是錯的。無論如何,HTML本身構造是不正確的,它阻止了獲取表單元素? – RajKon

+0

實際上它工作。謝謝。不知道爲什麼其他方法不起作用。 – RajKon