需要帮助找到XPATH - Python

时间:2016-03-10 10:23:58

标签: python selenium xpath

尝试了不同的组合,来自find.element_by_xpath和by_id,由于某种原因,我无法从此列表中选择第一个单选按钮。它说道路无法找到。

这是代码,我基本上需要先选择输入。

<li id="opc-shipping_method" class="section">
    <div class="step-title">
        <span class="number">4</span>
        <h3>Shipping Method</h3>
        <!--<a href="#">Edit</a>-->
    </div>
    <div id="checkout-step-shipping_method" class="step a-item" style="display:none;">
        <form id="co-shipping-method-form" action="">
<div id="checkout-shipping-method-load">



<dl class="sp-methods">

        <div class="method-option">
            <ul>
                                                                <li>

                                                        <label for="s_method_ups_65">


                                <input name="shipping_method" type="radio" value="ups_65" id="s_method_ups_65" class="radio"/>



                                                                    UPS Saver                                                                                                            <span class="price">€33.34</span>                                                                    </label>
                                                </li>
                                                                <li>

                                                        <label for="s_method_ups_07">


                                <input name="shipping_method" type="radio" value="ups_07" id="s_method_ups_07" class="radio"/>



                                                                    UPS Express                                                                                                            <span class="price">€35.42</span>                                                                    </label>
                                                </li>
                                                                <li>

                                                        <label for="s_method_ups_08">


                                <input name="shipping_method" type="radio" value="ups_08" id="s_method_ups_08" class="radio"/>



                                                                    UPS Expedited                                                                                                            <span class="price">€158.37</span>                                                                    </label>
                                                </li>
                                                                <li>

                                                        <label for="s_method_ups_54">


                                <input name="shipping_method" type="radio" value="ups_54" id="s_method_ups_54" class="radio"/>



                                                                    UPS Worldwide Express PlusSM                                                                                                            <span class="price">€226.73</span>                                                                    </label>
                                                </li>
                                </ul>
        </div>
        </dl>

1 个答案:

答案 0 :(得分:1)

尝试

driver.find_elements_by_xpath('//input[@type="radio"]')[0]

driver.find_element_by_id("s_method_ups_65")

driver.find_element_by_xpath('//label[@for="s_method_ups_65"]/input')