2012-10-23 46 views
3

我以前使用过selenium RC,但我是webdriver的新手。 我在我的应用程序中有三个链接。通知,消息和连接。 单击通知时,会显示通知下拉框。在单击消息时,将显示消息下拉框,并在单击连接时显示连接下拉框。 在脚本中,我单击通知链接,等待通知下拉框,然后断言通知收件箱。消息和连接依次相同。 通知序列正常工作。在消息中,它会单击消息链接,然后挂起等待消息放置框链接。我知道这一点,因为我已经在每一行之后放置了打印命令。 赫雷什是我的代码:在IE中运行的Selenium webdriver脚本挂在Firefox中

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个小时,仍然没有错误。

请让我知道,以防您需要更多信息来帮助我解决此问题。

谢谢!

+0

经历正是你的一样的情况。无法弄清楚该怎么办..你解决了这个问题吗?还是有工作?请帮帮我....! :-( – Mike

回答

0

这似乎与Facebook登录有一些联系。你是否正确切换窗口句柄?此外,您默认的默认时间是30秒,所以我不确定您的脚本是否可以运行11个小时而不会出错。

您可以尝试以下

1)我猜测className("message")不存在,你的脚本实际上是得到后停留在这一步,而不是一步。其中涉及点击。

driver.findElement(By.id("notifications-page-button")).click(); 
wait.until(driver.findElement(By.id("messages-page-button")));#<<-- Changed the element to wait for 

//The code works untill here. But on the next command that clicks messages link, it hangs 
driver.findElement(By.id("messages-page-button")).click(); 
wait.until(ExpectedConditions.presenceOfElementLocated(By.className(("username")))); 

2)删除等元素

driver.findElement(By.id("notifications-page-button")).click(); 
#removed this wait for element 

//The code works untill here. But on the next command that clicks messages link, it hangs 
driver.findElement(By.id("messages-page-button")).click(); 
wait.until(ExpectedConditions.presenceOfElementLocated(By.className(("username")))); 

UPDATE


请试试这个...

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

//The code works untill here. But on the next command that clicks messages link, it hangs 
driver.findElement(By.id("messages-page-button")).click(); 
wait.until(driver.findElement(By.id("connections-page-button"))); # changed it to wait for the element that you will next work with 

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

另外,如果您provid e Web元素的HTML代码片段,您不能确定它是否位于定位器中,我们可以帮助解决这个问题。

+0

是的,切换正常,甚至在登录后在主窗口上执行第一个点击命令,但之后什么都不做,如果隐含的等待时间是30秒,那么应该是这样。我已经指定的参数是30秒 – Pooja

+0

做了一些编辑,更新了我的回答 – Amey

+0

感谢您的回复。不幸的是,我试了两个建议,但它没有工作:( – Pooja

1

以前版本的Selenium Webdriver发生了类似的事情。我也无能为力,发生在我身上的事情。最后,升级到最新版本的Selenium帮助我变好,但是因为2.25。0是最新的,我将至少为您呈现我使用的解决方法,直到更新解决它。

每当我需要点击一个按钮,什么都没有发生(至于你)。所以解决方法是,点击按钮时,我也发送Enter关键事件。

更具体:

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

是的,它的解决方法。是的,它不好。是的,它帮助了我。

而且也:不,我不知道这样做的根本原因,因为硒的更新我的情况帮我...

+0

感谢您的回应。至少有一个人面对这个问题,并能理解我的情况:)。我尝试了你建议的解决方法,但没有帮助。我添加了命令以在单击命令之后按Enter键。但是我使用Selenium 2.25.0和FF 15.你认为我应该使用Selenium 2.22和FF 13或之前的解决方案来工作吗? – Pooja

+0

我试图降级到硒2.22和FF 13.试图解决你的建议,但它没有工作:( – Pooja

+0

太糟糕了...这是我知道的唯一的解决方法,它对我工作 –

相关问题