我怎么可以点击Primefaces数据表表行HtmlUnitDriver使用Selenium? [英] How can I click on Primefaces Datatable Table Row with HtmlUnitDriver using Selenium?

查看:142
本文介绍了我怎么可以点击Primefaces数据表表行HtmlUnitDriver使用Selenium?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个简单的code:

Here is a sample code:

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class PrimeFaces {

    public static void main(String[] args) throws Exception {
        HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(true);
        WebDriverWait wait = new WebDriverWait(htmlUnitDriver,10);
        htmlUnitDriver.get("http://primefaces-rocks.appspot.com/ui/datatableComplex.jsf");
        htmlUnitDriver.findElementById("j_idt44:j_idt45_row_0").click();
        WebElement until = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ui-dialog-title-j_idt44:j_idt59")));
    }

}

下面,ID: j_idt44:j_idt45_row_0 是在本页面发现的第一行:的 http://primefaces-rocks.appspot.com/ui/datatableComplex.jsf

Here, id: j_idt44:j_idt45_row_0 is for the first row found in this page: http://primefaces-rocks.appspot.com/ui/datatableComplex.jsf

当你点击此行,你会看到一个窗口弹出包含具有ID的元素: j_idt44:j_idt59

When you click on this row, you will see a window popping up containing an element with id: j_idt44:j_idt59

但随着HtmlUnitDriver这个元素是不可见的监守我觉得无论是HtmlUnitDriver不点击的行,或事件侦听器没有被触发。

But with HtmlUnitDriver this element is not visible becuase I think either HtmlUnitDriver is not clicking on the row, or the event listener is not being triggered.

我该如何解决这个问题呢?

How can I solve this problem?

推荐答案

似乎是一个时间问题。我用下面的code:

Seems like a timing problem. I used the following code:

driver = new HtmlUnitDriver();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.get("http://primefaces-rocks.appspot.com/ui/datatableComplex.jsf");

driver.findElement(By.id("j_idt44:j_idt45_row_0")).click();
assert driver.findElement(By.id("j_idt44:j_idt59")).isDisplayed();

工作完全正常的我。

works perfectly fine for me.

请注意,与10秒超时,它的每一次失败对我来说。

Note that with a 10 second timeout, it fails for me every time.

这篇关于我怎么可以点击Primefaces数据表表行HtmlUnitDriver使用Selenium?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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