Reputation: 31
I have used selenium RC in the past but I am new to webdriver. I have three links in my app. Notifications, messages and connections. On clicking notifications, notifications drop box is displayed. On clicking messages, messages drop box is displayed and on clicking connections, connections drop box is displayed. In the script, I click notifications link, wait for notifications drop box and then assert for notifications dropbox. Same for messages and connections in sequence. The notification sequence works correctly. In messages, it clicks on messages link and then hangs on the wait for messages drop box link. I know this since I had put print command after every line. Heres is my code:
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()
Heres the HTML for messages section:
<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>
Heres the HTML for notifications section:
<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>
The above code works on IE. So looks like the problem is not that it is not able to find the element. I am using Selenium 2.25.0. I have tried various versions of FF including 3.6, 7, 11, 13, 15 and 16. But none of them worked. Also, the script just hangs. It does not even throw an error in eclipse. I had once let my script run for around 11 hours and still no error.
Please let me know in case you need further information to help me resolve this issue.
Thanks!
Upvotes: 3
Views: 2796
Reputation: 8548
This seems to have some connection with a Facebook Login. Are you correctly switching between window handles? Also what is your implicit time out, by default it is set at 30 seconds, so I am not sure if your script can run for 11 hours without erroring out.
Can you try these
1) I am guessing, className("message")
does not exist, and your script is actually getting stuck at that step and not the step after. Which involves the click.
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) Remove that wait for element
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
Please try this ...
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"))));
Also, if your provide an HTML snippet of the web elements, which you are not sure abt the locator, we can help figure it out.
Upvotes: 0
Reputation: 14748
Something similar happened to me in previous versions of Selenium Webdriver. And I was also clueless, whats happening to me. Eventually, updating to newest version of Selenium helped me for good, but because 2.25.0 is the latest, I will at least present you the workaround I was using until update solved it
Whenever I needed to click a button, nothing happened (as to you). So the workaround was, that when clicking button, I also send Enter
key event to it.
To be more specific:
WebElement buttonWhereClickingDoesNotWork = driver.findElement(By.id("messages-page-button");
buttonWhereClickingDoesNotWork.click();
buttonWhereClickingDoesNotWork.sendKeys(Keys.ENTER);
Yes, its workaround. Yes, its not nice. And yes, it did help me.
And also: No, I do not know the root cause of this, since update of Selenium helped me in my case...
Upvotes: 1