從最簡單的任務開始,即從C#應用程序捕獲Firefox中的URL。它看起來使用user32.dll Windows API函數不能像在IE中捕獲URL的方法那樣工作。如何從C#應用程序自動化Firefox?
10
A
回答
3
WebAii可以自動火狐,包括設置和獲取URL
4
我應該需要做的AutoHotkey的URL的捕捉,比如,我會立即發送Ctrl + L(放焦點在地址欄和亮點內容)和Ctrl + C(將選擇複製到剪貼板)。然後,您只需閱讀剪貼板即可獲取信息。
對於更復雜的任務,我會使用Greasemonkey或iMacros擴展,可能是由類似的鍵盤快捷鍵觸發的。
1
一個微軟的工具,我跑進:
UI自動化,爲.NET 3.5 http://msdn.microsoft.com/en-us/library/aa348551.aspx
這部分是一個例子: http://msdn.microsoft.com/en-us/library/ms771286.aspx
我沒有UI間諜在我的電腦詢問Firefox,所以我不知道這是否會幫助解決您的user32.dll問題。
2
它似乎是非常beta-ey,但有人爲mozrepl構建了.net connector。實際上,mozrepl codebase只是移動到github。但是mozrepl可以讓你向Firefox的XUL環境下發命令。
4
WatiN支持Firefox。
2
嘗試硒(在谷歌測試引擎 - http://seleniumhq.org/)您可以錄製任務(網頁UI相關的)在Firefox和轉換記錄做成C#源:)
1
可以使用硒的webdriver爲C#。
這是一個跨平臺的API,允許您控制各種使用API的Java,C#等瀏覽器。
代碼C#與Selenium WebDriver測試的附件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Interactions.Internal;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.IE;
using NUnit.Framework;
using System.Text.RegularExpressions;
namespace sae_test
{ class Program
{ private static string baseURL;
private static StringBuilder verificationErrors;
static void Main(string[] args)
{ // test with firefox
IWebDriver driver = new OpenQA.Selenium.Firefox.FirefoxDriver();
// test with IE
//InternetExplorerOptions options = new InternetExplorerOptions();
//options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
//IWebDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver(options);
SetupTest();
driver.Navigate().GoToUrl(baseURL + "Account/Login.aspx");
IWebElement inputTextUser = driver.FindElement(By.Id("MainContent_LoginUser_UserName"));
inputTextUser.Clear();
driver.FindElement(By.Id("MainContent_LoginUser_UserName")).Clear();
driver.FindElement(By.Id("MainContent_LoginUser_UserName")).SendKeys("usuario");
driver.FindElement(By.Id("MainContent_LoginUser_Password")).Clear();
driver.FindElement(By.Id("MainContent_LoginUser_Password")).SendKeys("123");
driver.FindElement(By.Id("MainContent_LoginUser_LoginButton")).Click();
driver.Navigate().GoToUrl(baseURL + "finanzas/consulta.aspx");
// view combo element
IWebElement comboBoxSistema = driver.FindElement(By.Id("MainContent_rcbSistema_Arrow"));
//Then click when menu option is visible
comboBoxSistema.Click();
System.Threading.Thread.Sleep(500);
// container of elements systems combo
IWebElement listaDesplegableComboSistemas = driver.FindElement(By.Id("MainContent_rcbSistema_DropDown"));
listaDesplegableComboSistemas.FindElement(By.XPath("//li[text()='BOMBEO MECANICO']")).Click();
System.Threading.Thread.Sleep(500);
IWebElement comboBoxEquipo = driver.FindElement(By.Id("MainContent_rcbEquipo_Arrow"));
//Then click when menu option is visible
comboBoxEquipo.Click();
System.Threading.Thread.Sleep(500);
// container of elements equipment combo
IWebElement listaDesplegableComboEquipos = driver.FindElement(By.Id("MainContent_rcbEquipo_DropDown"));
listaDesplegableComboEquipos.FindElement(By.XPath("//li[text()='MINI-V']")).Click();
System.Threading.Thread.Sleep(500);
driver.FindElement(By.Id("MainContent_Button1")).Click();
try
{ Assert.AreEqual("BOMBEO MECANICO_22", driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_LabelSistema\"]")).Text);
}
catch (AssertionException e)
{ verificationErrors.Append(e.Message);
}
// verify coin format $1,234,567.89 usd
try
{ Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelInversionInicial\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd"));
}
catch (AssertionException e)
{ verificationErrors.Append(e.Message);
}
try
{ Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelCostoOpMantto\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd"));
}
catch (AssertionException e)
{ verificationErrors.Append(e.Message);
}
try
{ Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelCostoEnergia\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd"));
}
catch (AssertionException e)
{ verificationErrors.Append(e.Message);
}
try
{ Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelcostoUnitarioEnergia\"]")).Text, "\\$((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})? usd"));
}
catch (AssertionException e)
{ verificationErrors.Append(e.Message);
}
// verify number format 1,234,567.89
try
{ Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.XPath("//*[@id=\"MainContent_RejillaRegistroFinanciero_ctl00_ctl04_labelConsumo\"]")).Text, "((,)*[0-9]*[0-9]*[0-9]+)+(\\.[0-9]{2})?"));
}
catch (AssertionException e)
{ verificationErrors.Append(e.Message);
}
System.Console.WriteLine("errores: " + verificationErrors);
System.Threading.Thread.Sleep(20000);
driver.Quit();
}
public static void SetupTest()
{ baseURL = "http://127.0.0.1:8081/ver.rel.1.2/";
verificationErrors = new StringBuilder();
}
protected static void mouseOver(IWebDriver driver, IWebElement element)
{ Actions builder = new Actions(driver);
builder.MoveToElement(element);
builder.Perform();
}
public static void highlightElement(IWebDriver driver, IWebElement element)
{ for (int i = 0; i < 2; i++)
{ IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("arguments[0].setAttribute('style', arguments[1]);",
element, "color: yellow; border: 2px solid yellow;");
js.ExecuteScript("arguments[0].setAttribute('style', arguments[1]);",
element, "");
}
}
}
}
相關問題
- 1. C#自動化應用程序
- 2. 自動化應用程序
- 3. 如何從C#WinForm應用程序自動登錄到桌面應用程序?
- 4. 如何從C#應用程序啓動應用程序?
- 5. Android:從應用程序內啓動Firefox
- 6. 如何使用Selenium自動化Firefox Mobile?
- 7. C/C++ GUI應用程序的自動化測試
- 8. 使用VBScript自動化應用程序
- 9. 如何在Office 2010自動化C#應用程序中更改啓動
- 10. 如何自動化桌面應用程序授權過程?
- 11. 如何實現使用web驅動程序在Firefox中記住自動化?
- 12. 應用程序洞察自動化
- 13. 自動並行化.net應用程序
- 14. Unity應用程序的UI自動化
- 15. 應用程序測試自動化
- 16. 如何使用appium自動化cocos2dx(Open GL View)應用程序
- 17. 如何使用selenium webdriver自動化Silverlight應用程序?
- 18. Google即時應用程序 - 如何使用Appium自動化
- 19. 從C++啓動C#.Net應用程序
- 20. 如何調用從C#應用程序
- 21. 尋找一個C++庫來自動化應用程序更新
- 22. 如何從我自己的android應用程序啓動電報應用程序?
- 23. 如何自動化iPhone應用程序生成?
- 24. 如何自動化iPhone應用程序的多個版本?
- 25. 如何爲Java Web應用程序自動化Javascript縮小?
- 26. 如何自動部署應用程序
- 27. 如何自動更新應用程序
- 28. 如何在啓動時啓動Firefox OS應用程序
- 29. 如何啓動C++ mfc應用程序
- 30. 自動阻止應用程序從啓動程序啓動