如何以编程方式“单击” Silverlight 超链接按钮 (WebAii)

发布于 2024-08-03 04:49:51 字数 665 浏览 10 评论 0原文

我目前正在使用 WebAii 自动化框架针对 Silverlight 3 应用程序编写一些用户界面测试。我是 Silverlight 新手,怀疑我缺少一些有关 HyperlinkBut​​ton 的信息。

该应用程序有一个 HyperlinkBut​​ton,我正在尝试编写导航到页面的代码,找到页面上的按钮,然后“单击”该按钮(然后导航到 HyperlinkBut​​ton 属性中指定的 NavigateUri)。

我不知道如何执行该点击。到目前为止我的代码(简化):

Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo("http://server/appname/");
var slApp = ActiveBrowser.SilverlightApps()[0];
var menu = slApp.FindName<StackPanel>("LinksStackPanel");
var linkicareabout = menu.Find.ByName<HyperlinkButton>("Some Cases");

我希望看到某种 Click() 操作,或可以在“linkicareabout”变量上调用的 Navigate() 方法,但我一定错过了它是如何完成的。

I'm currently using the WebAii automation framework to write some user interface tests against a Silverlight 3 application. I'm new to Silverlight and suspect that I'm missing some bit of information about the HyperlinkButton.

The application has a HyperlinkButton and I'm attempting to write code that navigates to the page, finds the button the page, then "clicks" that button (which will then navigate to the NavigateUri as specified in the HyperlinkButton's properties).

I can't figure out how to execute that click. The code I have thus far (simplified):

Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo("http://server/appname/");
var slApp = ActiveBrowser.SilverlightApps()[0];
var menu = slApp.FindName<StackPanel>("LinksStackPanel");
var linkicareabout = menu.Find.ByName<HyperlinkButton>("Some Cases");

I'd expect to see some sort of Click() action, or Navigate() method that I could invoke on the "linkicareabout" variable, but I must be missing how it's done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羁绊已千年 2024-08-10 04:49:51

您正在寻找的是 HyperlinkBut​​ton 之外的 User 对象。 WebAii 附带的所有控件都有该对象。这样您就可以对任何控件类型调用任何用户操作。

<代码>
linkicareabout.User.Click()

User 对象支持您能想到的任何用户操作并模仿真实的用户交互。查看文档 此处

What you are looking for is the User object off the HyperlinkButton. All controls that WebAii comes with have that object. This way you can invoke any user action on any control type.


linkicareabout.User.Click()

The User object supports any user action you can think of and mimic real user interactions. Check out the documention here.

遗弃M 2024-08-10 04:49:51

我自己无法做到这一点,只能编写自己的导航代码。对于 Firefox 和 IE,您只需使用 HtmlPage.Window.Navigate 导航到所需的 URL。

然而,Safari 和 Chrome 需要一些额外的工作。我必须使用隐藏的 HTML 组件和一些 javascript 互操作。

此解决方法是 详细信息请参见此处

基本上,它需要向包含 Silverlight 控件的 HTML 页面添加隐藏的锚点和按钮,然后通过调用 DOM 修改锚点并单击按钮。

 HtmlElement anchor = HtmlPage.Document.GetElementById("externalAnchor");
 HtmlElement button = HtmlPage.Document.GetElementById("externalButton");
 if ((anchor != null) && (button != null))
 {
     anchor.SetProperty("href", url);
     button.Invoke("click", null);
 }

I was unable to do this myself and instead, had to write my own navigation code. For Firefox and IE, you can just use HtmlPage.Window.Navigate to navigate to the desired URL.

However, Safari and Chrome need some extra work. I had to use hidden HTML components and some javascript interops.

This workaround is detailed here.

Basically, it entails adding a hidden anchor and button to the HTML page containing your Silverlight control, and then modifying the anchor and clicking the button via calls to the DOM.

 HtmlElement anchor = HtmlPage.Document.GetElementById("externalAnchor");
 HtmlElement button = HtmlPage.Document.GetElementById("externalButton");
 if ((anchor != null) && (button != null))
 {
     anchor.SetProperty("href", url);
     button.Invoke("click", null);
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文