0

我正在使用 selenium webdriver,我试图在其中拖放表格的一列。但是,一旦我拖放列,我就会收到错误消息“元素不再附加到 DOM”。下面是我用于拖放元素的代码

            WebElement draggable = objectIdentifierType(
                          objectIdentificationKeyword, objectValue);

            WebElement droppable = GetBrowserDriver.driver.findElement(By.xpath(objectData));                 
            /*WebElement droppable = objectIdentifierType(
                          objectIdentificationKeyword, objectValue);*/
            if (draggable != null) {
                   System.out.println(draggable.getText()+"Draged element");
                   System.out.println(droppable.getText()+"Droped element");
                   //System.out.println(droppable.getText());
                   new Actions(GetBrowserDriver.driver).dragAndDrop(
                                 draggable,droppable).build()
                                 .perform();

                    HTMLReport.bw.write("<script type='text/javascript'>addDetailRow('"
                            + GenericFunctions.testCaseName + "','"
                            + HTMLReport.testcaseTABLESNO() + "','\""
                            + "Drag Value: "
                            + draggable.getText()
                            + "','Drop Value \""
                            + droppable.getText()
                            + "\" ','"
                            + "','Passed' )</script>");
                   // new
                   // Actions(GetBrowserDriver.driver).dragAndDrop(draggable,
                                 // droppable);
                   String actualResult = "The Slider value is changed to the expected value.";
                   CreateExcel updatePassed = new CreateExcel();
                   updatePassed.updatePassedTestSteps(actualResult,
                                 expectedResult, objectData);
4

1 回答 1

0

显然,您通过此操作更改了 DOM。您需要分配draggable.getText()droppable.getText()我不太熟悉java的字符串,但我认为这应该可行:

if (draggable != null) {
    String draggableText = draggable.getText();
    String droppableText = droppable.getText();
    //continue your code from here using new variables

PS对不起我的英语不好

于 2013-07-01T21:38:45.950 回答