How to automate a 'triple-click' using Jav

2019-05-10 06:42发布

问题:

I'm automating tests that deal with text, and I need to be able to select an entire paragraph. In order to do this (at this point) I need to automate a triple click. Any idea how to do that?

This is what I've attempted so far, neither works:

action.click().click().click().perform();

//and...

for(int i=0; i<3; i++) {
    action.click().perform();
}

回答1:

It's been a while, but I believe this was the solution that ended up working for me:

import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

public void tripleClick() {
    Actions action = new Actions(driver);
    WebElement cursor = driver.findElement(By.xpath("//div[contains(@id,'rCursor')]"));
    int count = 3;

    while(count>0){
        action.click(cursor).perform();
        count -= 1;
    }
}

Hope that helps!