0

问题:无法在表中使用 sendKeys。

我在做什么:我有从 dojo 创建的表。能够获取列,当我打印它们时,我可以看到每列的值。我想为一列设置值,在我的情况下这是第二个值,我想将它设置为“testselenium”字符串。sendkeys 正常工作,但在这种特殊情况下不能正常工作。

我正在使用 Java 使用 selenium 进行测试。

以下是我正在尝试使用的一段代码。

<pre><code>

    List<WebElement> findElements = driver
            .findElement( By.xpath("//div[starts-with(@id,'mytable')]"))
            .findElement( By.xpath("//div[starts-with(@class,'dojoxGridContent')]"))
            .findElements(By.tagName("td"));

    // Got the column elements

    Iterator<WebElement> iterator = findElements.iterator();
    int counter = 0;
    // Iterating over column i.e. td elements
    while(iterator.hasNext()){
        counter++;
        WebElement next = iterator.next();
        if(counter == 2){
            Actions action = new Actions(driver);
            action.doubleClick(next);
            action.perform();
            next.sendKeys("testselenium");
            break;
        }
        System.out.println(next.getText());
    }

</pre></code>

有没有人有同样的想法。

4

1 回答 1

0
<pre>
if(counter == 2){
Actions action = new Actions(driver);              
action.doubleClick(next);                        
**action.sendKeys("testselenium");**
action.perform();
break;
}     
</pre>

在执行呼叫之前使用操作中的 sendKeys 对我有用。

于 2013-04-24T12:27:22.960 回答