【问题标题】:How Can I found Xpath when clicking on a button a row is added to the JQGrid单击按钮时如何找到 Xpath 将一行添加到 JQGrid
【发布时间】: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


【解决方案1】:

JQuery 会是一个选项吗?然后您可以跳过 XPath 并使用 JQuery 处理 DOM 元素。

另外,检查一下您是否真的必须点击日历?你不能只为它提供你选择的价值吗?从外观上看,它使用文本字段作为支持。如果您只找出它存储日期的格式,您应该能够直接将该值添加到该文本框,而无需模拟点击和其他内容。

【讨论】:

  • 根据设计我们只能通过日历选择日期。没有提供输入文本框。他们在 JQGrid 表中使用了默认的日期选择器。
  • 可以选择 JQuery 吗?
猜你喜欢
  • 2013-02-24
  • 1970-01-01
  • 2011-11-13
  • 1970-01-01
  • 2014-04-30
  • 2019-06-24
  • 1970-01-01
  • 2016-08-04
  • 1970-01-01
相关资源
最近更新 更多