Niloy Rony
Niloy Rony

Reputation: 632

Selenium Python XPATH how to select input field which is in post form?

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

Answers (2)

Ananth
Ananth

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

frianH
frianH

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

Related Questions