Sendkeys to Webelement导致新标签\窗口打开

时间:2015-12-15 11:19:46

标签: java selenium-webdriver

我使用Selenium-webdriver(使用Java)自动化'facebook'尝试将字符串发送到文本字段(作为对帖子的评论)将导致在浏览器中打开几个选项卡(chrome)以及浏览器的新窗口。 有人遇到过这种奇怪的行为吗?

这是我的代码:

WebElement postBox = driver.findElement(By.xpath("(//div[contains(@title,'Write a comment')])[1]"));
postBox.sendKeys("testing testing, 1.. 2.. 3..");

1 个答案:

答案 0 :(得分:0)

我建议您使用cssSelector,因为xpath可能会失败,具体取决于您的浏览器。

CssSelector:By.CSSselector(.innerwrap textarea)

有关CSSselector here的更多信息。