需要以下html代码

时间:2016-12-08 23:03:09

标签: python selenium-webdriver

以下是我需要一个独特的XPath的HTML代码。 Firebug给了我一个类似

的xpath
.//*[@id='service_dlg']/form/p[4]/span/input[1] [For Essential]

.//*[@id='service_dlg']/form/p[4]/span/input[2] [For Enhanced]等。

我需要类似[@name = 'Essential']的东西,这样我就不需要在代码中编写多个xpath。我想从函数中传递essential, enhanced and premium之类的值。

<p>
<label style="vertical-align:top">Feature Pack:</label>
<span style="display:inline-block">
<input name="pack" value="Essential" type="radio">
<label class="feature">Essential</label>
<input name="pack" value="Enhanced" type="radio">
<label class="feature">Enhanced</label>
<input name="pack" value="Premium" type="radio">
<label class="feature">Premium</label>
<br>
<input name="featurepack" value="u" type="checkbox">
<label class="feature">URL Filtering</label>
<br>
<input name="featurepack" value="t" type="checkbox">
<label class="feature">Threat Prevention</label>
<br>
<input name="featurepack" value="w" type="checkbox">
<label class="feature">Wildfire</label>
<br>
</span>

1 个答案:

答案 0 :(得分:0)

尝试Enhanced

//input[@value='Enhanced']

要使其成为通用的并将值作为函数参数接收,请尝试以下操作:

driver.find_element_by_xpath("//input[@value='%s']" % value) # where value is function parameter, can be Essential, Enhanced or Premium