如何在多个下拉Python硒中的Xpath中唯一地标识React js ID?

时间:2018-10-30 02:09:58

标签: javascript python python-3.x selenium dropdownbox

[硒的新手]

我正在使用python硒单击网页上的下拉列表。我可以使用xpath成功做到这一点。我要单击的所有下拉菜单都与课程完全一样,在select之后,每个下拉菜单的数字都会更改:

gender = driver.find_element_by_xpath('//*[@id="react-select-7--value"]/div[2]/input')
gender.send_keys('Male')
gender.send_keys(Keys.DOWN)
gender.send_keys(Keys.DOWN)
gender.send_keys(Keys.RETURN)

如何唯一标识react-select-20--value才能单击下拉菜单?

下面是“最高” div类中的html,它封装了我要在此react-select-20--value中单击的Gender

其他下拉菜单也具有类似的结构。

<div class="col-md-2">
    <div class="form-input  form-group has-error">
    <span class="glyphicon glyphicon-asterisk"></span>
    <label for="customer.gender" class="control-label">Patient Gender</label>
    <span class="input-group">
    <div class="Select is-searchable Select--single">
    <div class="Select-control">
    <span class="Select-multi-value-wrapper" id="react-select-20--value">
    <div class="Select-placeholder">Select:</div>
    <div class="Select-input" style="display: inline-block;">
    <input aria-activedescendant="react-select-20--value" aria-expanded="false" aria-haspopup="false" aria-owns="" role="combobox" value="" style="box-sizing: content-box; width: 5px;">
    <div style="position: absolute; top: 0px; left: 0px; visibility: hidden; height: 0px; overflow: scroll; white-space: pre; font-size: 14px; font-family: Helvetica, Arial, sans-serif; font-weight: 400; font-style: normal; letter-spacing: normal; text-transform: none;">
    </div>
    </div>
    </span>
    <span class="Select-arrow-zone">
    <span class="Select-arrow"></span>
    </span>
    </div>
    </div>
    </span>
    <span class="help-block">Select Gender</span>
    </div>
</div>

编辑:这不是重复的问题,因为我可以选择下拉列表,但是当链接ID更改时不能选择下拉列表。

0 个答案:

没有答案