2

My application has the following snippet of code:

<form id="frmDepartmentCreation" name="frmDepartmentCreation" method="post" 
      action="">
    <table class="formStyle_1" border="0" cellpadding="0" cellspacing="10" 
            width="100%">
        <tr>
            <td>&nbsp;</td>
            <td align="left"><label class="formBtn_1">
                <input  id="Submit" name="Submit" value="Submit" type="submit" 
                        onclick="return val()"/></label>
                <input type="hidden" name="hdnbutton" id="hdnbutton" value=""/>
            </td>
        </tr>
    </table>
</form>

What is the xpath of "Submit" button considering the above code?

2 Answers 2

5

You don't need XPath and I wouldn't recommend using xpath in this situation. In this case id can be used as below:

selenium.click("id=Submit"); 

The above code would do what you want.

Sign up to request clarification or add additional context in comments.

3 Comments

Agreed. XPath is less readable (and by that measure, less maintainable)...I am partial towards using CSS. XPath, however, is useful for tables.
Yes, If there is ID available it's better to use id instead of xpath. css path is faster than xpath
simple xpath for Submit button is as follows: //input[@id = 'Submit']
0

//form[@id = 'frmDepartmentCreation']//input[@id = 'Submit'] is one way (starting with // is done as I assume that snippets is part of a larger document.

3 Comments

+1 Correct. Altough given a DTD declaring @id of type ID, one could use id('Submit')
Right, I thought about using id but with the question being tagged as selenium rc I was not sure that is supported so I went with the posted expression.
Your xpath is right. But, it is not a good practice to use this sort of long xpath. The better to use only //input[@id='Submit']

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.