Selenium Python无法单击选择按钮

时间:2018-04-15 02:32:48

标签: python selenium element

我正在练习自动化技能并尝试在亚马逊网站上实现自动化。目前,我遇到的问题是我的自动化测试脚本没有点击选择按钮,因此下拉列表将显示其项目的各种大小。我可以使用其他任何选项,那么Selenium可以点击按钮吗?

我尝试了以下方法,但没有运气。

driver.find_element_by_css_selector('#dropdown_selected_size_name > span > span').click()

以下是我试图测试的HTML:

//*[@id="dropdown_selected_size_name"]/span/span。  

            <option value="-1" id="native_size_name_-1" data-a-id="size_name_-1" selected="">         
                        Select

            </option>

            <option value="0,B01KXHF98M" class="dropdownAvailable" data-a-css-class="dropdownAvailable" id="native_size_name_0" data-a-id="size_name_0" data-a-html-content="18 oz (532 ml) Standard Mouth">
                18 oz (532 ml) Standard Mouth
            </option>

            <option value="1,B01KXHF626" class="dropdownAvailable" data-a-css-class="dropdownAvailable" id="native_size_name_1" data-a-id="size_name_1" data-a-html-content="21 oz (621 ml) Standard Mouth">
                21 oz (621 ml) Standard Mouth
            </option>

            <option value="2,B01KXHF34W" class="dropdownAvailable" data-a-css-class="dropdownAvailable" id="native_size_name_2" data-a-id="size_name_2" data-a-html-content="24 oz (710 ml) Standard Mouth">
                24 oz (710 ml) Standard Mouth
            </option>

            <option value="3,B01N9TFE5L" class="dropdownUnavailable" data-a-css-class="dropdownUnavailable" id="native_size_name_3" data-a-id="size_name_3" data-a-html-content="12 oz (354 ml) Standard Mouth">
                12 oz (354 ml) Standard Mouth
            </option>


    </select>

额外的htmls

#variation_size_name > span.twister-dropdown-highlight.transparentTwisterDropdownBorder > span

        

            <option value="-1" id="native_size_name_-1" data-a-id="size_name_-1" selected="">  
                        Select    
            </option>

            <option value="0,B01KXHF98M" class="dropdownAvailable" data-a-css-class="dropdownAvailable" id="native_size_name_0" data-a-id="size_name_0" data-a-html-content="18 oz (532 ml) Standard Mouth">
                18 oz (532 ml) Standard Mouth
            </option>

            <option value="1,B01KXHF626" class="dropdownAvailable" data-a-css-class="dropdownAvailable" id="native_size_name_1" data-a-id="size_name_1" data-a-html-content="21 oz (621 ml) Standard Mouth">
                21 oz (621 ml) Standard Mouth
            </option>       
            <option value="2,B01KXHF34W" class="dropdownAvailable" data-a-css-class="dropdownAvailable" id="native_size_name_2" data-a-id="size_name_2" data-a-html-content="24 oz (710 ml) Standard Mouth">
                24 oz (710 ml) Standard Mouth
            </option>

            <option value="3,B01N9TFE5L" class="dropdownUnavailable" data-a-css-class="dropdownUnavailable" id="native_size_name_3" data-a-id="size_name_3" data-a-html-content="12 oz (354 ml) Standard Mouth">
                12 oz (354 ml) Standard Mouth
            </option>


    </select><span tabindex="-1" id="dropdown_selected_size_name" data-a-class="aui-variation  a-fastclick-disable" class="a-button a-button-dropdown aui-variation  a-fastclick-disable" style="min-width: 0%;"><span class="a-button-inner"><span class="a-button-text a-declarative" data-action="a-dropdown-button" role="button" tabindex="0" aria-hidden="true"><span class="a-dropdown-prompt">                                                
                       Select                    
            </span></span><i class="a-icon a-icon-dropdown"></i></span></span></span>
    </span>

我要选择的元素: <a tabindex="-1" href="javascript:void(0)" data-value="{&quot;stringVal&quot;:&quot;1,B01KXHF626&quot;}" id="native_dropdown_selected_size_name_2" class="a-dropdown-link">21 oz (621 ml) Standard Mouth</a>

0 个答案:

没有答案