如何从HTML下方的弹出式下拉菜单中选择值

细语

我有弹出警报,其中包含下拉菜单中的下拉值。这些值将基于先前的选择列表。谁能帮助我使用python selenium模块从此下拉列表中选择值。

<div class="none">
    <div id="selectfavcolor">
        <h3 class="popupTitle">Select your favourite color</h3>

        <div class="clearFix pdLR15">
            <!--newSelectBox start-->
            <div class="newSelectBox">
                <div class="dd-select-main clearFix">
                    <div id="myDropdown"></div>
                    <label id='SlctColorError' class='dispNone SlctErrors error'></label>
                </div>

                <div class="pdTB15 alRgt">
                    <a href="javascript:;" id="savecolor" class="darkYellowBtn">Save</a>
                </div>
            </div>
            <!--newSelectBox end-->
        </div>
    </div>
</div>

我已经这样尝试过了。但这不起作用。

select_make = driver.find_element_by_id('myDropdown')
for option in select_make.find_elements_by_tag_name('SlctColorError'):
    if option.text == 'Blue':
        option.click() # select() in earlier versions of webdriver
        break
鳄鱼

假设Blue当执行任何其他操作时该选项出现在屏幕上,
一种更好的方法是等待它出现在屏幕上并且可单击之后,再单击它。

一个示例(代码是Java的,因为我不了解Phyton,但我相信您会设法将其转换为Phyton):

final By blueOption = By.xpath( "//*[ text() = 'Blue' ]" ); 

/* wait max. 10 seconds then throw an exception if the option has't appeared */
WebDriverWait wait = new WebDriverWait(driver, 10); 

wait.until( ExpectedConditions.elementToBeClickable( blueOption )).click();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章