Java - 如何验证当鼠标悬停在按钮上时是否显示替代文本?
我正在测试一个用 Javascript 编写的网站,方法是在 Eclipse 中编写(非常简单)Java 测试并将其作为 JUnit 测试运行。
由于我对 Java 几乎完全陌生,所以我到处都遇到问题。例如:在网页上,有一些按钮带有替代文本,如果鼠标悬停在按钮上半秒钟,就会出现替代文本。
我使用 Selenium IDE 1.0.10 来获取 scLocator ID,但它不会获取替代文本弹出窗口的 ID。如果在 Selenium IDE 中使用 "mouseOver"
或 "mouseOverAndWait"
,则不会发生任何情况。测试不会失败,因为元素存在,但替代文本没有出现。
我可以使用什么 java 命令来实现 mouseOver
?我想一旦找到元素我就可以使用 "assertScElementPresent('', 10*SECONDS);"
,但是我可以在 java 中使用什么命令来模拟鼠标悬停在按钮上?
我希望这个问题很清楚并且有意义。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的意思是说“标题”属性,而不是替代文本吗?将鼠标悬停在按钮上会显示标题。如果浏览器找不到图像资源,则使用 img alt 属性(alt 属性)——然后显示 alt 文本。我不知道您的 id 是什么,因此根据您的详细信息,我假设您正在使用 LinkButton 控件,其中包含 Image 控件。我有以下两个解决方案。如果您稍后使用该变量,请通过使用访问器和操作来使用第一个答案。如果您只是验证 UI,则使用第二个答案,即单独的 Assert(验证命令)。
ASP.NET 代码:
渲染的 HTML 代码:
<输入名称=“TextBox1”类型=“文本”id=“TextBox1”/>
#1(访问器和操作):
命令:storeText
目标:xpath=//img[@id='Image1']/@title
值:var_img_title
命令:type
目标:TextBox1
值:${var_img_title}
#2(断言):
命令:assertAttribute
目标:xpath=//img[@id='Image1']/@title
值:按钮
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