我有这样的HTML:
upload_input = $driver.find_element(:id, "//input[@name = 'coupon_file']")
$driver.execute_script "$('input').show();"
upload_input.send_keys file
我正在尝试上传文件但收到错误:
没有这样的元素:无法找到元素
答案 0 :(得分:1)
upload_input = $ driver.find_element(:id," //输入[@name =' coupon_file']")
其实你做错了。 您尝试使用 <div class='input-group date' id="datetimepicker">
@Html.TextBoxFor(model => model.Date, new { style = "background-color: #fff;", id = "date", @Class = "form-control input-sm", required = "required", @readonly = "readonly" })
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
@Html.ValidationMessage("Date", new { style = "color: red" })
<script type="text/javascript">
$(function () {
$('#datetimepicker').datepicker({
multidate: true,
multidateSeparator: ",",
maxViewMode: 1,
datesDisabled: [@Html.Raw(ViewBag.dis)],
orientation: "bottom left",
keyboardNavigation: false,
clearBtn: true,
daysOfWeekDisabled: "0,6",
endDate: @Html.Raw(ViewBag.enddate),
startDate: '+2d'
});
});
</script>
语法查找上传元素,但提到的xpath
定位符不正确。它应该如下: -
id
或者您可以使用upload_input = $driver.find_element(:xpath, "//input[@name = 'coupon_file']")
upload_input.send_keys file
定位器轻松找到此上传元素,而不是: -
name