首页 > 解决方案 > 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.

标签: pythonseleniumselenium-webdriver

解决方案


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')

推荐阅读