How to automate a 'triple-click' using Java & Selenium?

廉价感情. 提交于 2019-12-07 18:06:50

问题


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!



来源:https://stackoverflow.com/questions/22363633/how-to-automate-a-triple-click-using-java-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!