【问题标题】:Is it possible to handle two webelements simultaneously with Selenium 2 Webdriver?是否可以使用 Selenium 2 Webdriver 同时处理两个 webelements?
【发布时间】:2011-12-19 09:10:42
【问题描述】:

将 textarea 包裹在父 div 元素中。 仅当鼠标悬停在父级上时,此文本区域才可见。

我尝试了以下方法:

WebElement pr = driver.findElement(parent);
Actions builder = new Actions(driver);

builder.moveToElement(pr).peform();
driver.findElement (textarea).sendKeys (text);

但是当 webdriver 开始寻找子文本区域时,它失去了对父文本区域的关注。 当父元素悬停时,必须做一些可以负担向子元素发送文本的事情。有可能吗?

【问题讨论】:

    标签: testing automation webdriver selenium-webdriver


    【解决方案1】:

    您必须使用 javascript - 我认为 webdriver 一次不能处理多个元素。
    我看到的你的选择:

      1234563
    1. 通过 javascript 设置 textarea 的文本,注意您不会触发任何事件,因为您实际上并没有输入任何内容。

    【讨论】:

    • 谢谢,第一个变体有效! js.executeScript("document.getElementById('" + id + "').style.display = 'block';");
    【解决方案2】:

    您也许可以使用 Actions API 来完成这两项操作,将鼠标悬停在父项上,然后像下面这样输入子项。

    Actions builder = new Actions(driver);      
    WebElement parent = driver.findElement(By.id("parent"));
    WebElement child = driver.findElement(By.id("child"));
    Action hoverAndType = builder.moveToElement(parent)
                          .sendKeys(child, "Text to type in the child")
                          .build();
    hoverAndType.perform();
    

    【讨论】:

      猜你喜欢
      • 2017-08-14
      • 2017-04-13
      • 1970-01-01
      • 2012-01-04
      • 2018-04-01
      • 1970-01-01
      • 2018-01-10
      • 1970-01-01
      • 2012-06-28
      相关资源
      最近更新 更多