如何使用Java& amp;来自动化“三击”硒? [英] How to automate a 'triple-click' using Java & Selenium?

查看:227
本文介绍了如何使用Java& amp;来自动化“三击”硒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自动化处理文本的测试,我需要能够选择整个段落。为了做到这一点(此时),我需要自动进行三次点击。知道如何做到这一点吗?

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();
}


推荐答案

已经有一段时间了,但是我相信这是最终为我工作的解决方案:

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;
    }
}

希望有所帮助!

这篇关于如何使用Java&amp; amp;来自动化“三击”硒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆