Python Selenium无法更改Select元素值

时间:2016-11-07 20:34:16

标签: python selenium html-select

我有一个包含两个选项的Select元素:CashCash,前者是默认选项。我已经尝试了传统的所有内容以及我能想到的任何其他内容,但我无法将此值更改为pay_type_dropdown = driver.find_element_by_xpath(path_ending_in_select) pay_type_dropdown.click() # Have tried with and without clicking. Never seemed to make a difference. pay_type_select = Select(pay_type_dropdown) pay_type_select.select_by_visible_text('Cash') 。我的代码如下:

select_by_value('CASH')

但我也尝试了select_by_index(1) - 选项标记的值 - 和pay_type_dropdown = driver.find_element_by_xpath(path_ending_in_select) pay_type_dropdown.click() elems = pay_type_dropdown.find_elements_by_tag_name('option') elems[1].click() ,以及

elems = pay_type_dropdown.find_elements_by_xpath(path_ending_in_select + '/option')
elems[1].click()

click()

也无济于事。下拉框打开(如果使用<div class="z-form-row" data-bind="visible: settings.tender.active, 'if': settings.tender.active"> <div class="z-form-field"> <label data-bind="_t: 'cart_options_payment_label'">I'll pay with:</label> <select data-bind="value: settings.tender.selected, options: settings.tender.types, optionsText: 'label', optionsValue: 'id', valueAllowUnset: true"><option selected="selected" value="CARD">Credit / Debit Card</option><option value="CASH">Cash</option></select> </div> <i class="z-row-icon z-icon-card" data-bind="css: tenderTypeIcon()"></i> </div> 函数单击),但未选择其他值。过去没有任何事情发生,也没有错误。 它不在一个单独的框架中,因为我能够与其他所有内容进行交互,而无需转移到正确的框架中。非常感谢任何帮助,谢谢。

编辑:这是相关的HTML。

.typewriter h1 {
  text-align: center;
  overflow: hidden;
  font-size: 100%;
  border-right: .15em solid #fff;
  white-space: nowrap;
  /* keeps content in one line */
  letter-spacing: .15em;
  animation: typing 2.5s steps(22, end), blink-caret .75s step-end;
}
.typewriter h2 {
  font-size: 100%;
  white-space: nowrap;
  overflow: hidden;
  border-right: .15em solid black;
  -webkit-animation: typing 2s steps(26, end), blink-caret 1s step-end infinite;
  -webkit-animation-delay: 3s;
  -webkit-animation-fill-mode: both;
  -moz-animation: typing 2s steps(26, end), blink-caret 1s step-end infinite;
  -moz-animation-delay: 3s;
}
/* The typing effect */

@keyframes typing {
  from {
    width: 0
  }
  to {
    width: 9em;
  }
}
@keyframes blink-caret {
  from, to {
    border-color: transparent
  }
  50% {
    border-color: #000;
  }
}

0 个答案:

没有答案