0

我正在尝试为 Facebook 应用程序编写测试。我想验证 Facebook 分享。所以在我的代码中,我能够打开共享窗口。当我单击共享时,我想获得 Javascript 响应。在此响应中有“post_id”,我需要导航到已发布的共享。我怎样才能在 Selenium 中得到这个响应?选择 shareButton 的代码:

WebElement shareButton = driver.findElement(By.xpath("//input[@value='Teilen']"));

当我这样做时shareButton.click,它会分享。我怎样才能在这里得到回复?

感谢任何帮助:)

4

1 回答 1

0

从您提供的链接中,它说收到响应时它将填充<p id='msg'></p>

function callback(response) {
          document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
        }

所以这意味着你所要做的就是等待元素有一些东西:

WebElement myElementWithID = (new WebDriverWait(driver, 10))
  .until(new ExpectedCondition<WebElement>(){
    @Override
    public WebElement apply(WebDriver d) {
        return d.findElement(By.id("msg")).getText().contains("Post ID: ");
    }});

完成后,只需处理来自d.findElement(By.id("msg")).getText().

于 2013-02-07T23:13:13.590 回答