在 IE 中运行的 Selenium Webdriver 脚本在 Firefox 中挂起

标签 selenium webdriver selenium-webdriver

我过去使用过 selenium RC,但我是 webdriver 的新手。 我的应用程序中有三个链接。通知、消息和连接。 单击通知时,会显示通知下拉框。单击消息时,将显示消息下拉框;单击连接时,将显示连接下拉框。 在脚本中,我单击通知链接,等待通知下拉框,然后断言通知下拉框。对于顺序消息和连接也是如此。 通知序列工作正常。在消息中,它单击消息链接,然后卡在等待消息投递箱链接上。我知道这一点,因为我在每一行后面都放置了打印命令。 这是我的代码:

 driver.findElement(By.xpath("//a[@id='notifications-page-button']")).sendKeys("\n");
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='notifications-dropdown-list']//li//div[@class='message']")));
Assert.assertTrue(isElementPresent(By.xpath("//div[@id='notifications-dropdown-list']//li//div[@class='message']")), "Notifications drop box was not displayed");

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[@id='messages-page-button']")));

driver.findElement(By.xpath("//a[@id='messages-page-button']")).sendKeys("\n");
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@class='sf_messages_list dropdown']//li//div[@class='message']"))); //This is the line where the script hangs. If I remove this line and the next line and continue with just the click commands, they work. But when I have this line and the next, the remaining click commands are not executed

Assert.assertTrue(isElementPresent(By.xpath("//div[@class='sf_messages_list dropdown']//li//div[@class='message']")), "Messages drop box was not displayed");

wait.until(ExpectedConditions.presenceOfElementLocated(By.id("connections-page-button"))); 
driver.findElement(By.id("connections-page-button")).click()

这是消息部分的 HTML:

<li class="icon mm open">
<a id="messages-page-button" class="mm" href="#">
<span class="icon"></span>
<span class="badge hidden_elem">
<strong>
<em>0</em>
</strong>
</span>
</a>
<div class="dropdown-holder">
<div class="sf_messages_list dropdown" data-eventprefix="mainmenu_messages">
<div class="tb-dropdown-header">Messages</div>
<div class="tb-dropdown-body" data-url="/messages/dropdown">
<div class="document-title" style="display: none; !important"> - Dropdown Messages</div>
<div id="messages_list_view_76345" class="message-threads-listview">
<ul>
<div class="no_items hidden_elem">
</div>
</div>
<div class="tb-dropdown-footer" style="display: block;">
</div>
<span class="shadow-hide"></span>
</div>
</li>

这是通知部分的 HTML:

<li class="icon mm">
<a id="notifications-page-button" class="mm" href="#">
<span class="icon"></span>
<span class="badge hidden_elem">
<strong>
<em>0</em>
</strong>
</span>
</a>
<div class="dropdown-holder">
<div id="notifications-dropdown-list" class="sf_notifications_list dropdown" data-eventprefix="mainmenu_notifications">
<div class="tb-dropdown-header">Notifications</div>
<div class="tb-dropdown-body" data-url="/notifications/dropdown"></div>
<div class="tb-dropdown-footer">
<a class="view_all" href="/notifications/view">View All Notifications</a>
</div>
</div>
<span class="shadow-hide"></span>
</div>
</li>

以上代码适用于 IE。所以看起来问题不在于它无法找到该元素。 我正在使用 Selenium 2.25.0。我尝试过 FF 的各个版本,包括 3.6、7、11、13、15 和 16,但都不起作用。 此外,脚本只是挂起。它甚至不会在 eclipse 中抛出错误。我曾经让我的脚本运行了大约 11 个小时,但仍然没有错误。

如果您需要更多信息来帮助我解决此问题,请告诉我。

谢谢!

最佳答案

在以前版本的 Selenium Webdriver 中,类似的事情也发生在我身上。我也一无所知,我发生了什么事。最终,更新到最新版本的 Selenium 对我有好处,但因为 2.25.0 是最新的,我至少会向您展示我正在使用的解决方法,直到更新解决它

每当我需要点击一个按钮时,什么也没有发生(对于你来说)。所以解决方法是,当单击按钮时,我还向其发送 Enter 键事件。

更具体地说:

 WebElement buttonWhereClickingDoesNotWork = driver.findElement(By.id("messages-page-button");
buttonWhereClickingDoesNotWork.click();
buttonWhereClickingDoesNotWork.sendKeys(Keys.ENTER);

是的,它的解决方法。是的,这不太好。是的,它确实对我有帮助。

而且:不,我不知道其根本原因,因为 Selenium 的更新在我的情况下帮助了我......

关于在 IE 中运行的 Selenium Webdriver 脚本在 Firefox 中挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13031218/

相关文章:

ruby - selenium-webdriver 并等待页面加载

java - 使用构建器模式和 Selenium 通过不同的条件组合执行不同的搜索

java - 如何单击带有文本的元素作为编辑?

java - Selenium 通过鼠标悬停处理不同元素的相同链接文本

c# - Selenium C# : How to pull value from input element

python - Selenium 测试中如何选择第一个li元素?

java - Selenium Java - 文本字段验证和空值的日期验证

c# - selenium webdriver C# 多线程

javascript - 如何等待整个页面加载完毕?

java - Selenium 网络驱动程序 : not able to find the element on the 2nd page.