我写了硒代码来更新我的小组,如下


我必须先移至必须设置的组的div
编辑然后将显示编辑,删除链接以编辑该细节
组。
之后,我必须移动到“编辑”按钮并单击它


以下是我的div结构

HTML代码

<tr>
                <td class="new-action-group">
                    <div class="new-list-anchor"><a href="http://localhost/groupc/view/378" title="View Group">Operational </a></div>
                    <div class="new-action-menu" id="GroupActionMenu-Operational">
                        <div class="new-action-menu-placeholder"></div>
                        <span class="new-action-menu-arrow"></span>
                        <ul class="new-action-menu-ul">
                            <li><a href="javascript:;" class="action-delete delete_action" rel="http://localhost/groupc/delete/378" title="Delete Group"><em class="icon16 icon16-delete"></em></a></li>
                            <li><a href="http://localhost/groupc/edit/378" class="action-edit" title="Edit Group"><em class="icon16 icon16-edit"></em></a></li>
                            <li><a href="http://localhost/groupc/view/378" class="action-view" title="View Group"><em class="icon16 icon16-magnify"></em></a></li>
                        </ul>
                    </div>
                </td>
                <td><span class="normalTip" title="Display Name">Operational</span></td>
</tr>
<tr>
                <td class="new-action-group">
                    <div class="new-list-anchor"><a href="http://localhost/groupc/view/377" title="View Group">Purchasing </a></div>
                    <div class="new-action-menu" id="GroupActionMenu-Purchasing">
                        <div class="new-action-menu-placeholder"></div>
                        <span class="new-action-menu-arrow"></span>
                        <ul class="new-action-menu-ul">
                            <li><a href="javascript:;" class="action-delete delete_action" rel="http://localhost/groupc/delete/377" title="Delete Group"><em class="icon16 icon16-delete"></em></a></li>
                            <li><a href="http://localhost/groupc/edit/377" class="action-edit" title="Edit Group"><em class="icon16 icon16-edit"></em></a></li>
                            <li><a href="http://localhost/groupc/view/377" class="action-view" title="View Group"><em class="icon16 icon16-magnify"></em></a></li>
                        </ul>
                    </div>
                </td>
                <td><span class="normalTip" title="Display Name">Purchasing</span></td>
</tr>


影像检视



硒代码

Actions action = new Actions(driver);
   action.moveToElement(driver.findElement(By.id("GroupActionMenu-"+groupName)))
   .moveToElement(driver.findElement(By.className("action-edit"))).click().build().perform();
   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
   groupname.clear();
   groupname.sendKeys(groupName);
   btnAddNewGroup.submit();


此代码可以编辑某些组,但是在编辑某些组时会引发以下错误。

错误

SEVERE: Error While Edit group with name HRorg.openqa.selenium.interactions.MoveTargetOutOfBoundsException: Offset within element cannot be scrolled into view: (0, 0): http://localhost/groupc/edit/378
Command duration or timeout: 0 milliseconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'Sneha-PC', ip: '192.168.2.59', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_51'
Session ID: 3ef7e223-52b0-4bf5-8f34-5806d7a84c31
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=30.0}]


搜索此错误后,我知道该代码尝试单击不可见的元素,但我不知道同一代码如何可用于一个组而对于另一个组却无法执行,我无法找到导致此问题的原因。

最佳答案

Stack Question得到了答案,这对我有用

  WebElement element = driver.findElement(By.xpath("//div[@id='GroupActionMenu-'+groupName']/ul/li[1]/a"));
  JavascriptExecutor js = (JavascriptExecutor) driver;
  js.executeScript("arguments[0].click();", element);


希望这对其他人有帮助...!

10-06 14:43