Reputation: 632
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.
Upvotes: 1
Views: 515
Reputation: 797
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.
Upvotes: 1
Reputation: 7563
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')
Upvotes: 2