I am testing a site written in Javascript, by writing (very simple) Java tests in Eclipse and running them as JUnit tests.
As I am almost completely new to Java, I am encountering problems all over the place. For example: on the webpage, there are a few buttons that have开发者_开发知识库 alt-text that appears if the mouse is hovered over the buttons for half a second.
I use Selenium IDE 1.0.10 to get the scLocator IDs, but it does not pick up the ID for the alt-text pop-up. If, in the Selenium IDE, I use "mouseOver"
or "mouseOverAndWait"
, nothing happens. The test does not fail, as the element is present, yet the alt-text does not appear.
What java command can I use for mouseOver
? I guess I can use "assertScElementPresent('', 10*SECONDS);"
once I find the element, but what command can I use in java to simulate a mouse hover over a button?
I hope the question is clear and makes sense.
Did you mean to say "title" attribute, instead of alternate text? Hovering over a button displays the title. The img alt attribute (alt attribute) is used if the browser cannot find the image resource--it then displays the alt text. I don't know what your ids are, so I'm assuming you are using a LinkButton control with an Image control inside of it given your details. I have two solutions below. If you're using this for using the variable later, then use the first answer by using an Accessor and an Action. If you are just validating the UI, then use the second answer, which would be an Assert (validation command) alone.
ASP.NET code:
<asp:LinkButton ID="LinkButton1" runat="server"> <asp:Image ID="Image1" runat="server" AlternateText="img text" ToolTip="button" ImageUrl="http://www.google.com/intl/en_com/images/srpr/logo1w.png" /> </asp:LinkButton>
Rendered HTML code:
<a id="LinkButton1" href="javascript:__doPostBack('LinkButton1','')"><img id="Image1" title="button" src="http://www.google.com/intl/en_com/images/srpr/logo1w.png" alt="img text" /></a> <input name="TextBox1" type="text" id="TextBox1" />
#1 (Accessor & Action):
Command: storeText
Target: xpath=//img[@id='Image1']/@title
Value: var_img_title
Command: type
Target: TextBox1
Value: ${var_img_title}
#2 (Assert):
Command: assertAttribute
Target: xpath=//img[@id='Image1']/@title
Value: button
精彩评论