【发布时间】:2016-08-31 10:42:21
【问题描述】:
我正在尝试查找在单击按钮时添加的行的 Xpath。在第一行和第一列中,我需要单击 datepicker 并选择日期。我怎样才能找到这个日期选择器元素的 Xpath。以下是我的代码
`<table id="list" class="ui-jqgrid-btable" cellspacing="0"
cellpadding="0" border="0" style="border: 0px none ! important;
width: 2205px;" tabindex="0" role="grid" aria-multiselectable="false" aria-labelledby="gbox_list">
<tbody>
<tr class="jqgfirstrow" style="height:auto" role="row">
<td style="height:0px;width:100px;" role="gridcell"></td>
<td style="height:0px;width:70px;" role="gridcell"></td>
<td style="height:0px;width:120px;" role="gridcell"></td>
<td style="height:0px;width:200px;" role="gridcell"></td>
<td style="height:0px;width:120px;" role="gridcell"></td>
<td style="height:0px;width:140px;" role="gridcell"></td>
<td style="height:0px;width:65px;" role="gridcell"></td>
<td style="height:0px;width:65px;" role="gridcell"></td>
<td style="height:0px;width:70px;" role="gridcell"></td>
<td style="height:0px;width:160px;" role="gridcell"></td>
<td style="height:0px;width:70px;" role="gridcell"></td>
<td style="height:0px;width:160px;" role="gridcell"></td>
<td style="height:0px;width:170px;" role="gridcell"></td>
<td style="height:0px;width:100px;" role="gridcell"></td>
<td style="height:0px;width:100px;" role="gridcell"></td>
<td style="height:0px;width:130px;" role="gridcell"></td>
<td style="height:0px;width:70px;" role="gridcell"></td>
<td style="height:0px;width:130px;" role="gridcell"></td>
<td style="height:0px;width:70px;" role="gridcell"></td>
<td style="height:0px;width:150px;display:none;" role="gridcell"></td>
</tr>
<tr id="1" class="ui-widget-content jqgrow ui-row-ltr ui-state-
highlight disableRow" tabindex="0" role="row" aria-selected="true"
editable="1">
<td rowspan="1" aria-describedby="list_effectiveDate" style="" role="gridcell">
<input id="1_effectiveDate" class="editable hasDatepicker border-
red" type="text" name="effectiveDate" style="width: 98%;" role="textbox" readonly="readonly"></td>
`
我试过下面的代码:
`driver.findElement(By.xpath(".//*[@id='1']/td[1]")).toString();
driver.findElement(By.id("1_effectiveDate")).click();
driver.findElement(By.xpath(".//*[@id='ui-datepicker-div']/table/tbody/tr[5]/td[2]/a")).click();`
【问题讨论】:
-
不清楚你的意思。您是否正在编写某种机器人/阅读器,它需要找到某个控件并模拟点击它?请提供更多背景信息。
-
是的。我必须选择并单击它。我正在尝试查找 [id="1_effectiveDate"] 的 Xpath。它是 JQgrid 的默认日期选择器。它是输入字段。我必须在日期选择器中选择日期。我在xpath下面试过: driver.findElement(By.xpath(".//*[@id='1']/td[1]")).toString(); driver.findElement(By.id("1_effectiveDate")).click(); driver.findElement(By.xpath(".//*[@id='ui-datepicker-div']/table/tbody/tr[5]/td[2]/a")).click();
-
可以选择 JQuery 吗?然后您可以跳过 XPath 并使用 JQuery 处理 DOM 元素。
标签: javascript java selenium-webdriver junit