3

I'm really struggling to automate some drag and drop functionality in a web app. All I need to do is click a link on a top menu bar, hold down on it and select the first menu option. It works fine in Chrome but I need it to work in FF. Currently using FF 37 and Selenium 2.45. My code:

    driver.switchTo().defaultContent();
    driver.switchTo().frame(0);
    Actions action = new Actions(driver);

    //click 'Content' button, this will expose the 'New' button
    WebElement contentDropDownButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='topPane']/div[1]/div/*//*//*[text()[contains(.,'Content')]]")));
    action.moveToElement(contentDropDownButton).clickAndHold();
    action.perform();

    //capture 'New' in a WebElement and then click and hold on it
    WebElement newButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[starts-with(@id, 'fw_dijit_UIPopupMenuItem')][text()[contains(.,'New')]]")));
    action.moveToElement(newButton).clickAndHold();
    action.perform();

Like I say, works fine in Chrome. What would be the best approach to handling this and can someone suggest code? I don't think I actually need to 'click' or 'hold' on either of the Content or New buttons as a real interation will work with a simple mouse hover. I'm just not sure how to recreate this with webdriver.

1

To perform a 'mouse hover' action, you need to concatenate all of the actions that you want to achieve in one go.

With the actions object you should first move the menu title, and then move to the sub menu item and click it.

Below is my attempt at sample code to perform Mouse hover action using your paths;

Actions actions = new Actions(driver);
WebElement contentDropDownButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='topPane']/div[1]/div/*//*//*[text()[contains(.,'Content')]]")));
actions.moveToElement(contentDropDownButton);

WebElement newButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[starts-with(@id, 'fw_dijit_UIPopupMenuItem')][text()[contains(.,'New')]]")));
actions.moveToElement(newButton);
actions.click().build().perform();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.