Reputation: 93
This question is a continuation of my last question (which can be found here). The issue that I'm having now trying to click a logout button using Selenium. Continuing from my last post, I'm trying to switch to a new window that pops up by searching the page for the logout button. I'm having trouble actually getting Selenium to recognize that button. Here's what I have for my method:
it "can go to Ultratime", focus: true do
@ie_driver.find_element(:link, "My Resources").click
sleep 5
@ie_driver.switch_to.frame(@ie_driver.find_element(:css, 'iframe[src="https://controller.nd.edu/ultratime/insidend/"]'))
@ie_driver.find_element(:class,"single").click
@window = @ie_driver.window_handles.detect { |w|
@ie_driver.switch_to.window(w)
wait.until { @ie_driver.find_element(:xpath, "//td[class='signbuts']") }
}
@ie_driver.switch_to.window(@window)
end
and the source code for the button that I'm trying to click:
<table class="table" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr style="height:20px">
<!--hr-->
<td class="td">
<button id="signbut" class="signbuts" title="" onblur="buttonBlur(this)"
onmouseout="buttonLeave(this)" onfocus="buttonFocus(this)"
onmouseover="buttonHover(this)" menuitem="ATW910"
onclick="signclick('W' ,'LOGOUT' ,'Logout' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'ATW' ,'910' ,'' ,'' )"></button>
</td>
<td class="td">
<button id="signbut" class="signbut" title="Leave the application"
onblur="buttonBlur(this)" onmouseout="buttonLeave(this)"
onfocus="buttonFocus(this)" onmouseover="buttonHover(this)" menuitem="ATW900"
onclick="signclick('D' ,'EXITSYS' ,'Quit' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'' ,'ATW' ,'900' ,'' ,'Leave the application' )">
</button>
</td>
</tr>
</tbody>
I show two different buttons just to show that I can't simply just look for the button id tag (which would make things so much easier). The error that I get when I try to run my script is a "Unable to find element "//td[class='signbuts']" " and as a result, it times out.
Any help would be greatly appreciated!!
Upvotes: 1
Views: 446
Reputation: 93
Figured out the issue. Somehow when I inspected the page source, the class name for that button was "signbuts". When I did this:
puts @ie_driver.page_source
for that button, it returned a class name of "signbut". I don't know as to why or how the page source had changed but it did. As soon as I ran it with the new class name it ran just fine.
Upvotes: 1
Reputation: 10329
Your sample code does not have a td
with a class name signbuts
, as can be seen from your error.
There is a button
with that class! However, when targeting an element by class, you should use the locator "classname". Something like:
@ie_driver.find_element(:classname, "signbuts")
Note I am not familiar with Ruby, so the syntax may be off.
Upvotes: 1