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>

Neither this returns element

WebElement form = driver.findElement(By.xpath("//body/h6/form[2]"));

nor

WebElement form = driver.findElement(By.name("catgy"));

Can you please help get the form element?

1 Answer 1

1

Try this

driver.findElement(By.cssSelector("form[name='catgy']"));
Sign up to request clarification or add additional context in comments.

2 Comments

that should have worked but it did not. Not sure what is wrong. Is the html itself constructed incorrect in anyway that is preventing from getting the form element?
actually it worked. Thanks. Not sure why other methods did not work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.