简体   繁体   English

Selenium-Python-Javascript下拉菜单选项值

[英]Selenium - Python - Javascript drop-down menu option value

Any thoughts on how to select and click on one of the two drop down options for this code snippet. 关于如何选择并单击此代码段的两个下拉选项之一的任何想法。 I have tried numerous approaches suggested in the forum, but could not get any to work. 我已经尝试了论坛中建议的多种方法,但没有任何效果。 Thanks in advance! 提前致谢!

 <div class="dropdownButton">
    <li id="Li1" class="r_dd1" onclick="showDropdown1(event,this);">
        <a class="r_ddh1" id="columnYearType">10 Years</a>
        <ul style="display: block;">
            <li><a href="javascript:SRT_stocFund.CurrentPeriod(5, this)">5&nbsp;<span class="columnType">Years</span></a></li>

            <li><a href="javascript:SRT_stocFund.CurrentPeriod(10, this)">
                10 <span class="columnType">
                    Years
                                        </span></a>
            </li>
        </ul>
    </li>
</div>

The xpath for the javascript:SRT_stocFund.CurrentPeriod 5 and 10 year options are: javascript:SRT_stocFund.CurrentPeriod 5年和10年选项的xpath是:

//*[@id="Li1"]/ul/li[1]/a

//*[@id="Li1"]/ul/li[2]/a

Perhaps the following will work: 也许以下方法会起作用:

Select select = new Select(driver.findElement(By.xpath("//path_to_drop_down")));
select.deselectAll();
select.selectByVisibleText("10 Years");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM