0
我也有同樣的html代碼:的webdriver - 通過值選擇選項與反斜槓
<select>
<option value="domain\00031477">Data 1</option>
<option value="domain\00031478">Data 2</option>
</select>
我想值這樣的選擇選項:
select.select_by_value(value)
但webdriver的沒有發現這一點。 我嘗試了雙反斜槓Keys.SEPARATOR。
更新:
def set_select_by_value(self, locator, value):
element = self.find_element(*locator)
select = Select(element)
select.select_by_value(value)
我打電話:
page.set_select_by_value((By.ID, "SomeId"), "domain\\00031478")
堆棧跟蹤:
self = <selenium.webdriver.support.select.Select instance at 0x03120468>
value = 'domain\\00031478'
def select_by_value(self, value):
"""Select all options that have a value matching the argument. That is, when given "foo" this
would select an option like:
<option value="foo">Bar</option>
:Args:
- value - The value to match against
throws NoSuchElementException If there is no option with specisied value in SELECT
"""
css = "option[value =%s]" % self._escapeString(value)
opts = self._el.find_elements(By.CSS_SELECTOR, css)
matched = False
for opt in opts:
self._setSelected(opt)
if not self.is_multiple:
return
matched = True
if not matched:
> raise NoSuchElementException("Cannot locate option with value: %s" % value)
E NoSuchElementException: Message: Cannot locate option with value: domain\00031478
我已添加到主要帖子 – bolatbekb