我正在自动化基于Windows的桌面应用程序(C#,LeanFT)。 单击按钮,在浏览器中打开一个网页。 如何验证网页是否已打开?
两种方式:
try..catch
那个错误
例如:
/*
* Desktop related logic that opens a browser
*/
// Use "Attach" to connect a new (or replacement) browser tab with the LeanFT test.
try {
IBrowser yourPage = BrowserFactory.Attach(new BrowserDescription
{
Title = "The title of the page",
Url = "https://thesitethatwasopened.com"
});
} catch (Exception ex) {
// the browser was not opened
}
/*
* Rest of the desktop app actions
*/
/*
* Desktop related logic that opens a browser
*/
// Use "GetAllOpenBrowsers" to get a collection of IBrowser instances that matches the description
IBrowser[] yourPages = BrowserFactory. GetAllOpenBrowsers(new BrowserDescription
{
Title = "The title of the page",
Url = "https://thesitethatwasopened.com"
});
/*
* Rest of the desktop app actions (maybe by making use of yourPages.Count
*/