[英]Is it possible to overwrite the value of <Input type = "hidden"> by letting user select from a drop down list?
[英]How to select or pass value into hidden type for drop down picklist on website?
[selenium和HTML上的新功能]
我想从网站上选择一个下拉菜单。 该type
是隐藏的。 我只想从下拉列表中传递或选择male
或female
,或将其传递给value
变量,我该怎么做?
我使用了chrome中的inspect元素来确定以下两行是选择值所需的行。
<div class="Select has-value is-clearable is-searchable Select--single">
<input name="customer.gender" type="hidden" value="female">
我从chrome获取了xpath并尝试传递一个值,但没有成功:
gender = driver.find_element_by_xpath("//*[@id='app']/div/div[1]/div[4]/div/div[2]/form/div[1]/div/div[2]/div[3]/div[2]/div/span[2]/div/input")
gender.send_keys('male')
上面div
元素的整个HTML是:
<div class="Select has-value is-clearable is-searchable Select--single">
<input name="customer.gender" type="hidden" value="female">
<div class="Select-control">
<span class="Select-multi-value-wrapper" id="react-select-5--value">
<div class="Select-value">
<span class="Select-value-label" role="option" aria-selected="true" id="react-select-5--value-item">Female</span>
</div>
<div class="Select-input" style="display: inline-block;">
<input aria-activedescendant="react-select-5--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 aria-label="Clear value" class="Select-clear-zone" title="Clear value">
<span class="Select-clear">×</span>
</span>
<span class="Select-arrow-zone">
<span class="Select-arrow"></span>
</span>
</div>
</div>
先感谢您。
编辑:
我从下拉列表中单击的HTML,但未选择任何值:
<div class="Select is-searchable Select--single">
<div class="Select-control">
<span class="Select-multi-value-wrapper" id="react-select-5--value">
<div class="Select-placeholder">Select:</div>
<div class="Select-input" style="display: inline-block;">
<input aria-activedescendant="react-select-5--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>
EDIT2:
下拉菜单中的HTML值
<div class="Select has-value is-clearable is-searchable Select--single">
<input name="customer.gender" type="hidden" value="male">
<div class="Select-control">
<span class="Select-multi-value-wrapper" id="react-select-5--value">
<div class="Select-value">
<span class="Select-value-label" role="option" aria-selected="true" id="react-select-5--value-item">Male</span>
</div>
<div class="Select-input" style="display: inline-block;">
<input aria-activedescendant="react-select-5--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 aria-label="Clear value" class="Select-clear-zone" title="Clear value">
<span class="Select-clear">×</span>
</span>
<span class="Select-arrow-zone"><span class="Select-arrow"></span></span>
</div>
</div>
您的下拉列表是一个React组件,我从此站点获得了示例。
// click on dropdown to expand options
dirver.find_element_by_xpath("//span[@id='react-select-5--value']/..").click();
// choose option
dirver.find_element_by_xpath(
"//span[@id='react-select-5--value']/../.." +
"//div[@role='option'][text()='%s']".format("Male")).click();
节点内的下拉选项: <div class="Select-menu-outer">
,单击该下拉列表后,此节点将附加到页面,选择一个选项后,将从页面取消附加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.