【问题标题】:webdriver.support.select - Select doesn't interact with the elementwebdriver.support.select - Select 不与元素交互
【发布时间】:2016-01-15 07:12:14
【问题描述】:

你好, 我有以下选择:

<div class="col-xs-12 col-md-6">
<label class="ph_label pointer city">
<span class="l citylbl">City</span>
<select class="cities custom-dropdown" data-validation-error-msg="You  must select a city" required="" name="city" disabled="disabled" data-validation="required">
<option value="">City</option>
<option value="Shanghai">Shanghai</option>
<option value="Beijing">Beijing</option>
<ul class="cities custom-dropdown" data-target-selector="select.cities" style="width: 293px;">
</label>
</div>

我正在尝试:

mySelect = Select(self.driver.find_element_by_name("city"))
mySelect.select_by_value("Shanghai")

当我看到测试运行时,selenium 穿过这个元素,好像一切正​​常,但实际上没有选择城市。 有什么想法吗?

【问题讨论】:

  • 任何其他带有name="city"的元素?
  • 只有一个具有此名称的元素!
  • 您是否尝试使用other locators 而不是名称来识别选择?好像你可以有其他元素 name="city"
  • 是的,比如 xpath、css 等。

标签: python select drop-down-menu selenium-webdriver


【解决方案1】:

我认为这是由于代码sn-p中的select被标记为禁用?

我尝试过使用 Watir-webdriver,如果有 disabled="disabled" 属性,我会得到你描述的行为。一旦我删除它,我想要的值就会被选中。

【讨论】:

  • 感谢@chefsim 的回复。与dropdown_city = self.driver.find_element_by_name("city") self.driver.execute_script('arguments[0].removeAttribute("disabled");', dropdown_city) 合作过
猜你喜欢
  • 2021-08-19
  • 2022-07-01
  • 1970-01-01
  • 2021-10-20
  • 1970-01-01
  • 2021-08-02
  • 2021-04-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多