我有弹出警告,弹出窗口中存在下拉值。值将基于先前的选择列表。任何人都可以帮我用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
答案 0 :(得分:0)
当执行任何其他操作时,假设选项Blue
出现在scereen上,
更好的方法是等到它出现在屏幕上并且可点击,然后点击它。
一个例子(代码是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();