无法获取警报弹出文本并在线程“main”中获取异常异常org.openqa.selenium.NoAlertPresentException:no alert open

时间:2017-12-17 04:45:51

标签: javascript java selenium ui-automation

尝试获取警报文本但在线程“main”中获得异常异常org.openqa.selenium.NoAlertPresentException:没有警告打开看起来像是一个模态框请查看代码以获取更多详细信息。

driver.findElement(By.name("submit_formset")).click();
Alert alt = driver.switchTo().alert()                                   
String without_data = alt.getText();
System.out.println("alert message when no data is entered:- "+without_data);

检查图片的网址,了解有关提醒的更多详情:https://i.stack.imgur.com/Rk7Ox.png

下面给出了当前弹出窗口的Html代码,让我知道更多关于此的说明:

<body>
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PF9P8P9" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<section class="main-section">
<footer class="main-footer noprint">
<script src="/static/newdesign/bower_components/foundation/js/foundation.min.js">
<script src="/static/newdesign/js/app.js">
<script src="/static/js/tables/responsive-tables.js">
<script type="text/javascript">
<div id="modal_message" class="reveal-modal" data-reveal="">
<script src="/static/slick/slick.min.js" type="text/javascript">
<script id="" type="text/javascript">
<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1157897200940118&amp;ev=PageView&amp;noscript=1"></noscript>
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front loadingDialog ui-draggable" style="display: none;" tabindex="-1" role="dialog" aria-describedby="loadingDialog" aria-labelledby="ui-id-1">
<div class="reveal-modal-bg" style="display: block;"></div>
<div id="formset-modal" class="fixed-size-reveal-modal-vehicle open" data-reveal="" style="display: block; opacity: 1; visibility: visible; top: 50px;">
<div class="row">
<div class="form-container">
<form data-add="true" method="post" action="/vehicle-check/add-vehicles/">
<input type="hidden" value="4J9zftpcYjBkGa93ZNCbEAClbxXAwhEFZVKsw9cKOb01KrtNbXMQviYEyzl4nT02" name="csrfmiddlewaretoken">
<input id="id_form-TOTAL_FORMS" type="hidden" value="1" name="form-TOTAL_FORMS">
<input id="id_form-INITIAL_FORMS" type="hidden" value="0" name="form-INITIAL_FORMS">
<input id="id_form-MIN_NUM_FORMS" type="hidden" value="0" name="form-MIN_NUM_FORMS">
<input id="id_form-MAX_NUM_FORMS" type="hidden" value="1000" name="form-MAX_NUM_FORMS">
<table style="width: 100%;">
<thead>
<tbody>
<tr class="even_row extra-row">
<td>
<select id="id_form-0-vehicle_type" required="" name="form-0-vehicle_type">
<option selected="" value="">---------</option>
<option value="2">VAN</option>
<option value="1">HGV</option>
<option value="3">LGV</option>
<option value="4">BUS</option>
<option value="5">PSV</option>
<option value="6">CAR</option>
<option value="7">Small Passenger</option>
</select>
</td>
<td>
<input id="id_form-0-registration" type="text" maxlength="10" required="" name="form-0-registration">
</td>
<td class="text-center">
<input id="id_form-0-can_attach_trailer" class="can_attach_trailer-field img-checkbox hidden" type="checkbox" name="form-0-can_attach_trailer" style="display: none;">
<img class="img-checkbox" src="/static/kinesisapp/images/empty-checkbox.png" alt="Checkbox" style="cursor: pointer;">
</td>
<td class="vehicle-groups">
<select id="id_form-0-groups" name="form-0-groups">
</td>
<td class="text-center">
<td class="text-center">
<input id="id_form-0-id" type="hidden" name="form-0-id">
</tr>
<tr class="due-date-fields even_row extra-row">
<tr class="error-messages hidden extra-row">
</tbody>
</table>
<div style="display:block; width: 330px;">
</form>
</div>
<div id="extra-form-fields" class="hidden">
</div>
</div>
<div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>
</body>

0 个答案:

没有答案