1

I have two form in same page like below

<form method="get">
     <input type="submit">
</form>

<form method="post">
     <input type="submit">
</form>

I am able to get last input field like

//input[last()]

I need to track the input field if it's a post method form input.

2 Answers 2

2

Try following xpath:

.find_element_by_xpath('//form[@method="post"]//input')

Or the css selector looks better:

.find_element_by_css_selector('form[method="post"] > input')
Sign up to request clarification or add additional context in comments.

Comments

1

You can get the list of forms using the XPath. Then extract its method attribute as below:

//form/[@method='post'] 

Once you have the form you can get the descendant as below:

//form/descendant::input[@type='submit']

This should return you the value.

Comments

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.