Bắt đầu với nhiệm vụ đơn giản nhất là chụp URL trong Firefox từ ứng dụng C#. Nó xuất hiện bằng cách sử dụng các hàm API Windows user32.dll sẽ không hoạt động như là cách tiếp cận để chụp URL trong IE.Làm thế nào bạn có thể tự động hóa Firefox từ ứng dụng C#?
Trả lời
WebAii có thể tự động FireFox, bao gồm thiết lập và lấy URL
Tôi có nên cần phải làm một chụp của URL với AutoHotkey, ví dụ, tôi sẽ gửi Ctrl + L (đặt trọng tâm vào thanh địa chỉ và nội dung nổi bật) và Ctrl + C (sao chép lựa chọn vào clipboard). Sau đó, bạn chỉ cần đọc clipboard để có được thông tin.
Đối với các tác vụ phức tạp hơn, tôi sẽ sử dụng phần mở rộng Greasemonkey hoặc iMacros, có thể được kích hoạt bằng các phím tắt tương tự.
Một Microsoft công cụ tôi chạy vào:
UI Automation, như một phần của NET 3,5 http://msdn.microsoft.com/en-us/library/aa348551.aspx
Dưới đây là một ví dụ: http://msdn.microsoft.com/en-us/library/ms771286.aspx
Tôi không có giao diện người dùng Spy trên pc của tôi để thẩm vấn Firefox, vì vậy tôi không biết nếu điều này sẽ giúp đỡ với vấn đề user32.dll của bạn.
Nó dường như rất beta-ey, nhưng ai đó đã tạo một .net connector cho mozrepl. Trên thực tế, các codebase mozrepl vừa chuyển đến github. Nhưng mozrepl cho phép bạn đưa ra các lệnh tới môi trường XUL của Firefox.
WatiN có hỗ trợ cho Firefox.
Hãy thử Selenium (động cơ thử nghiệm của Google - http://seleniumhq.org/) Bạn có thể ghi nhiệm vụ (trang web giao diện người dùng liên quan) thực hiện trong Firefox và chuyển đổi các ghi thành một nguồn C# :)
Bạn có thể sử dụng Selenium WebDriver cho C#.
Đây là API đa nền tảng cho phép bạn kiểm soát các trình duyệt khác nhau bằng cách sử dụng API cho Java, C#, trong số các trình duyệt khác.
Đính kèm mã C# với kiểm tra 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. Làm thế nào để bạn tự động hóa việc rút gọn Javascript cho các ứng dụng web Java của bạn?
- 2. Tự động hóa trình duyệt: Python + Firefox sử dụng PyXPCOM
- 3. Tự động hóa từ: Thay thế hình ảnh bằng C#
- 4. Tự động hóa firefox với python?
- 5. Làm thế nào tôi có thể tuần tự hóa đối tượng động vào JSON trong hành động C# MVC Controller?
- 6. Làm thế nào tôi có thể tải tệp jar tự động trong ứng dụng Android (4.0.3)
- 7. Android: Khởi động Firefox từ trong ứng dụng
- 8. Làm thế nào để đồng bộ hóa cá thể EC2 của tôi khi tự động hóa
- 9. Emacs: làm thế nào để bạn vô hiệu hóa tự động recentering?
- 10. Làm thế nào tôi có thể tự động hóa việc triển khai xây dựng trong jenkins?
- 11. Làm thế nào để bạn tự động hóa một số hành động thường xuyên để cải thiện năng suất?
- 12. Làm thế nào để bạn có thể làm cho biểu mẫu tối đa hóa với bất kỳ màn hình máy tính nào trong ứng dụng Windows Forms?
- 13. ứng dụng node.js có thể tự khởi động lại
- 14. Làm cách nào bạn có thể xem nhận xét bảng từ ứng dụng khách mysql?
- 15. Cách nhận Id gói của ứng dụng của bạn Tự động hóa UIA iOS
- 16. Tự động hóa nhà trong C#?
- 17. Làm thế nào tôi có thể tự động gọi một hàm tạo trong C#?
- 18. Bạn có thể tự động gán CFBundleDocumentTypes cho ứng dụng Cocoa của mình không?
- 19. Làm thế nào để bạn vô hiệu hóa tự động xây dựng trong xcode
- 20. Trình tải ứng dụng iTunes - tự động hóa
- 21. Làm cách nào để tạo một ứng dụng Camel độc lập có thể tự động tắt?
- 22. Có thể tự động hóa một ứng dụng Click-to-run không?
- 23. Làm thế nào để tuần tự hóa/deserialize một C# WCF DataContract đến/từ XML
- 24. Công cụ nào bạn đề xuất để tự động tạo ứng dụng của bạn?
- 25. Tự động hóa QA trên Ứng dụng Flex
- 26. Có thể tự động hóa triển khai ClickOnce không?
- 27. Làm thế nào bạn có thể đọc các giá trị từ một ứng dụng đang mở trong Windows?
- 28. Bạn có thể tạo kiểu nội dung trong Firefox như thế nào?
- 29. Delphi: Bạn tự động cập nhật các ứng dụng của mình như thế nào?
- 30. Làm cách nào tôi có thể tự động hóa tác vụ trong Xcode?