使用 webdriver 处理弹出对话框中的单选按钮
Handling radiobuttons in popup dialog using webdriver
对于 angular JS 应用程序中基于 Web 的对话框弹出窗口,它有 2 个单选按钮,其 xpath 如下:-
1. html/body/div[4]/div/div/div/div/div/div/div[2]/div/div/div/div/wizardviews/div[2]/div[1]/label/input
2.html/body/div[4]/div/div/div/div/div/div/div[2]/div/div/div/div/wizardviews/div[2]/div[2]/label/input1
该代码能够打开弹出窗口,但无法单击单选按钮,因为单击会启用同一对话框中的 "Next" 按钮。
下面是 HTML 代码以供进一步说明:-
<html class="js flexbox flexboxlegacy canvas canvastext webgl no-touch geolocation postmessage no-websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients no-cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths ng-scope" ng-app="AtlasEMPI" style="">
<head>
<body class="ng-scope modal-open" ng-controller="AtlasEMPICtrl">
<div class="container body-content divEMPIContainer">
<span class="select2-hidden-accessible" role="status" aria-live="polite"></span>
<span class="select2-hidden-accessible" role="status" aria-live="polite"></span>
<div class="row">
<div class="modal-backdrop fade in" ng-style="{'z-index': 1040 + (index && 1 || 0) + index*10}" ng-class="{in: animate}" modal-backdrop="" style="z-index: 1040;"></div>
<div class="modal fade ng-isolate-scope dialogClass in" ng-click="close($event)" ng-style="{'z-index': 1050 + index*10, display: 'block'}" ng-class="{in: animate}" role="dialog" tabindex="-1" modal-window="" window-class="dialogClass" size="lg" index="0" animate="animate" style="z-index: 1050; display: block;">
<div class="modal-dialog modal-lg" ng-class="{'modal-sm': size == 'sm', 'modal-lg': size == 'lg'}" style="">
<div class="modal-content" ng-transclude="">
<div class="ng-scope ng-isolate-scope" empiwizarddialog="" wizardoptions="empiwizardOption">
<div class="row">
<div class="empimodal-content" ng-class="(empiwizardOption.calledsource == 'usermgmt')?'empimodal-user':''">
<span class="adcfonticon-cancelcircle close-btn" ng-click="empiwizardOption.cancel(step)"></span>
<div class="empipanel" ng-class="(empiwizardOption.header ==false)?'empipanelnoborder' : 'empipanel'">
<div class="adcmodal-header" ng-show="empiwizardOption.header">
<div class="row">
<div class="col-sm-12">
<div style="padding-top:15px">
<div class="slide-frame ng-scope" ng-switch="getCurrentStep()">
<div class="ng-scope" ng-switch-when="confirmReject">
<wizardviews viewname="confirmReject">
<div class="row">
<hr class="empihorizontalruler empihorizontalrulertop">
<div class="row input-group createnewMPIDdidlaog">
<div class="col-sm-6">
<label class="lblradiorejectdialog">
<input class="rdoreject ng-pristine ng-valid" type="radio" value="createnewMPID" ng-model="radioreject" style="" name="1NM">
如前所述,弹出对话框中单选按钮的 xpath 是 "html/body/div[4]/div/div/div/div/div/div/div[2]/div/div/div/div/wizardviews/div[2]/div[1]/label/input",但代码无法找到该元素。
HTML 代码是:-"input type="radio" value="createnewMPID" ng-model="radioreject" class="rdoreject ng-pristine ng-valid" name="7MB" "
所以现在我将定位器用作 Xpath = "//input[@value='createnewMPID'
工作正常,脚本无法定位元素并单击。
对于 angular JS 应用程序中基于 Web 的对话框弹出窗口,它有 2 个单选按钮,其 xpath 如下:-
1. html/body/div[4]/div/div/div/div/div/div/div[2]/div/div/div/div/wizardviews/div[2]/div[1]/label/input
2.html/body/div[4]/div/div/div/div/div/div/div[2]/div/div/div/div/wizardviews/div[2]/div[2]/label/input1
该代码能够打开弹出窗口,但无法单击单选按钮,因为单击会启用同一对话框中的 "Next" 按钮。
下面是 HTML 代码以供进一步说明:-
<html class="js flexbox flexboxlegacy canvas canvastext webgl no-touch geolocation postmessage no-websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients no-cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths ng-scope" ng-app="AtlasEMPI" style="">
<head>
<body class="ng-scope modal-open" ng-controller="AtlasEMPICtrl">
<div class="container body-content divEMPIContainer">
<span class="select2-hidden-accessible" role="status" aria-live="polite"></span>
<span class="select2-hidden-accessible" role="status" aria-live="polite"></span>
<div class="row">
<div class="modal-backdrop fade in" ng-style="{'z-index': 1040 + (index && 1 || 0) + index*10}" ng-class="{in: animate}" modal-backdrop="" style="z-index: 1040;"></div>
<div class="modal fade ng-isolate-scope dialogClass in" ng-click="close($event)" ng-style="{'z-index': 1050 + index*10, display: 'block'}" ng-class="{in: animate}" role="dialog" tabindex="-1" modal-window="" window-class="dialogClass" size="lg" index="0" animate="animate" style="z-index: 1050; display: block;">
<div class="modal-dialog modal-lg" ng-class="{'modal-sm': size == 'sm', 'modal-lg': size == 'lg'}" style="">
<div class="modal-content" ng-transclude="">
<div class="ng-scope ng-isolate-scope" empiwizarddialog="" wizardoptions="empiwizardOption">
<div class="row">
<div class="empimodal-content" ng-class="(empiwizardOption.calledsource == 'usermgmt')?'empimodal-user':''">
<span class="adcfonticon-cancelcircle close-btn" ng-click="empiwizardOption.cancel(step)"></span>
<div class="empipanel" ng-class="(empiwizardOption.header ==false)?'empipanelnoborder' : 'empipanel'">
<div class="adcmodal-header" ng-show="empiwizardOption.header">
<div class="row">
<div class="col-sm-12">
<div style="padding-top:15px">
<div class="slide-frame ng-scope" ng-switch="getCurrentStep()">
<div class="ng-scope" ng-switch-when="confirmReject">
<wizardviews viewname="confirmReject">
<div class="row">
<hr class="empihorizontalruler empihorizontalrulertop">
<div class="row input-group createnewMPIDdidlaog">
<div class="col-sm-6">
<label class="lblradiorejectdialog">
<input class="rdoreject ng-pristine ng-valid" type="radio" value="createnewMPID" ng-model="radioreject" style="" name="1NM">
如前所述,弹出对话框中单选按钮的 xpath 是 "html/body/div[4]/div/div/div/div/div/div/div[2]/div/div/div/div/wizardviews/div[2]/div[1]/label/input",但代码无法找到该元素。 HTML 代码是:-"input type="radio" value="createnewMPID" ng-model="radioreject" class="rdoreject ng-pristine ng-valid" name="7MB" "
所以现在我将定位器用作 Xpath = "//input[@value='createnewMPID'
工作正常,脚本无法定位元素并单击。