无法在nobr标记

时间:2017-11-01 10:30:16

标签: selenium selenium-webdriver

无法找到带有输入标记的元素。需要在输入标记中找到元素。日食可以捕捉元素直到nobr而不是进一步。

input id="ServiceFromDate" class="inactvDtTmTxt" name="$PHCClaimSearch$pServiceFromDate" data-ctl="["DatePicker"]" data-formatting="yes" value="05/02/2017" data-value="5/2/2017" style="padding-right:17px;width:11.719em;" validationtype="date" data-change="[["refresh", ["thisSection","", "", "&=", "", ",",":event","","HCClaimSearch"]]]" data-display-value="05/02/2017" type="text"/>



//table[contains(@role,'presentation')][contains(@id,'pyActionArea')]//table[1]//table[contains(@role,'presentation')][contains(@section_index,'1')]//tbody//tr[2]//td[1]//following::nobr[1]//following::span[@id='$PHCClaimSearch$pServiceFromDateSpan']/input

driver.findElement(By.xpath("//input[@id='ServiceFromDate']")).sendKeys("04242015")

<table id="" role="presentation" section_index="1" cellspacing="0" cellpadding="0">
 <tbody>
 <tr>
 <tr>
 <td class="dataLabelWrite" style="height:24px;width:143px;">
 <td class="dataValueWrite" style="height:24px;width:190px;">
 <nobr>
<ins id="pega-calendar" style="display: none;" data-calendar="{"img":"webwb/pzspacercal_12860256145.gif!!.gif","locale":[["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59"],0,"M/d/yyyy","M/d/yyyy h:mm a","Today",["January","February","March","April","May","June","July","August","September","October","November","December"],["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],["AM","PM"],"Apply","Close"]}"/>
<script> var positionDatePickerIcn = function(control){ /* BUG-47098 - Following block filters out IE8(both quirks and standards modes) and IE9 (standards mode) */ var addMarginFlag = true; if(document.documentMode && navigator.userAgent.indexOf("Trident/4") > -1){ //IE8: skip for both standards and quirks mode addMarginFlag = false; } else if(document.documentMode && document.documentMode >= 9 && navigator.userAgent.indexOf("Trident/5") > -1){ //IE9: skip for standards mode addMarginFlag = false; } if (addMarginFlag) { var icnEle = control.lastChild; if(icnEle.tagName.toLowerCase() == 'img'){ icnEle.style.marginTop = '0px'; } } }; </script>
 <span id="$PHCClaimSearch$pServiceFromDateSpan" role="group" aria-label="Service From Date : " data-calendar="{"d":[0,0],"l":0}" style="display:inline-block; width:inherit;" onmouseover="pega.c.DatePicker.dtTmHvr(event);">
<input id="ServiceFromDate" class="inactvDtTmTxt" name="$PHCClaimSearch$pServiceFromDate" data-ctl="["DatePicker"]" data-formatting="yes" value="05/02/2017" data-value="5/2/2017" style="padding-right:17px;width:11.719em;" validationtype="date" data-change="[["refresh", ["thisSection","", "", "&=", "", ",",":event","","HCClaimSearch"]]]" data-display-value="05/02/2017" type="text"/>
<img class="inactvIcon" src="webwb/pzspacer_11792674401.gif!!.gif" data-ctl="["DatePicker"]" style="cursor:pointer;"/>
</span>
</nobr>
</td>
 <td class="dataLabelWrite" style="height:24px;width:125px;">
 <td class="dataValueWrite" style="height:24px;width:190px;">
 <td class="dataLabelWrite" style="height:24px;width:101px;">
</tr>
</tbody>
</table>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

问题在于HTML,至少在你粘贴在这里时。 该标记内有许多地方在双引号文本中包含双引号文本。例如input元素具有以下属性:

data-ctl="["DatePicker"]"

我发现此问题的其他属性:数据日历,数据更改 一旦我纠正了外部单引号存在问题的所有地方,我就可以使用Chrome开发人员工具中的Xpath找到输入

data-ctl='["DatePicker"]'

答案 1 :(得分:0)

正如您所提到的,您可以将元素捕获到<nobr>标记,而不是因为<ins>标记有style="display: none;",因此将使用 {{1} } 更改属性,然后按如下方式发送文本:

JavascriptExecutor