Tag: selenium

WebDriver使用Dragula在应用程序中拖放

我的公司有一个新的应用程序,包含拖放。 拖放是通过Dragula库完成的。 我正在尝试自动执行此function,但我没有运气。 我已经尝试了两个WebDriver内置的DragAndDrop()方法(我的理解是它通常不能与现代Web技术很好地工作)。 我尝试使用Actions构建自己的Drag and Drop。 我也尝试在javascript执行器中使用jquery。 这两种方法都没有奏效。 有人有什么建议吗?

Selenium:Firefox驱动程序,使用c#中的SelectElement从下拉列表中选择项目无法正常工作

我正在尝试通过使用显示的文本来尝试选择下拉列表中的值。 场景如下。 我的HTML看起来像。 Test1 Test2 Test3 Test4 通过使用selenium我想使用下拉列表中的第二个项目test2。 我为此编写的C#代码是。 FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(); service.FirefoxBinaryPath = @”C:\Program Files (x86)\Mozilla Firefox\firefox.exe”; string localURL = “http://localhost:82/”; using (IWebDriver driver = new FirefoxDriver(service)) { driver.Navigate().GoToUrl(localURL); var div = driver.FindElement(By.Id(“TestContainer”)); div.Click(); IWebElement dropDownListBox = div.FindElement(By.TagName(“select”)); SelectElement demoSelect = new SelectElement(dropDownListBox); demoSelect.SelectByText(“Test2”); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2)); } 除了以上所述,我甚至尝试逐个迭代选项并选择下面的相应项目也无济于事。 if (option.Text.Equals(“Test2”)) { option.Click(); driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2)); break; […]

在Saucelabs中使用Selenium远程Firefox webdriver安装扩展程序

问题 尝试在Saucelabs上远程执行Selenium测试期间安装Firefox浏览器扩展。 在本地执行测试时,扩展程序在Firefox中安装并处于活动状态,但在Saucelabs上的远程执行中,扩展名不会出现在已安装的扩展名列表中。 按照此Saucelabs 支持文章中概述的步骤操作。 建立 Selenium.Support v2.48.2或v2.49.0 Selenium.WebDriver v2.48.2或v2.49.0 Windows 10或7 Firefox 43 C#测试设置 private static FirefoxProfile CreateFirefoxProfile() { FirefoxProfile profile = new FirefoxProfile(); profile.AddExtension(“Tools/modify_headers-0.7.1.1-fx.xpi”); profile.SetPreference(“general.useragent.override”, “UA-STRING”); profile.SetPreference(“extensions.modify_headers.currentVersion”, “0.7.1.1-signed”); profile.SetPreference(“modifyheaders.headers.count”, 1); profile.SetPreference(“modifyheaders.headers.action0”, “Add”); profile.SetPreference(“modifyheaders.headers.name0”, “SampleHeader”); profile.SetPreference(“modifyheaders.headers.value0”, “test1234”); profile.SetPreference(“modifyheaders.headers.enabled0”, true); profile.SetPreference(“modifyheaders.config.active”, true); profile.SetPreference(“modifyheaders.config.alwaysOn”, true); profile.SetPreference(“modifyheaders.config.start”, true); return profile; } private static IWebDriver GetRemoteDriver() { var […]

无法加载类型’OpenQA.Selenium.Chrome.ChromeDriver’

使用WebDriver for .NET4.0 我运行程序时遇到TypeLoadException。 消息是: Could not load type ‘OpenQA.Selenium.Chrome.ChromeDriver’ from assembly ‘WebDriver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’.”:”OpenQA.Selenium.Chrome.ChromeDriver” 我的代码是单行… IWebDriver driver = new ChromeDriver(@”C:\webdriver”); //chomedriver.exe is in this 目录。 我使用的是最新版本2.33.0。 添加了对webdriver和webdriver.support的引用。 使用OpenQA.Selenium; 使用OpenQA.Selenium.Chrome; 还尝试了非客户端4框架目标,没有任何改进。

使用Selenium Webdriver和Windows身份validation(在Chrome中)C#/ ASP.Net

Google放弃了通过URL传递Windows凭据的支持,这为我打破了很多自动化。 (用户名:password@www.url.com) https://www.chromestatus.com/feature/5669008342777856 我发现有一个使用AutoItX dll的解决方案我添加了它并且在本地运行时工作正常,但是当部署到Web服务器时它不会发送击键。 这就是我所拥有的。 AutoItX.WinWaitActive(authenticateurl + ” – Google Chrome”, “”, 10); AutoItX.WinActivate(authenticateurl + ” – Google Chrome”); AutoItX.Send(AdminUsername + “{TAB}”); AutoItX.Send(AdminUserpass + “{ENTER}”); 知道为什么AutoItX在部署时不起作用? 是否有更好的替代方法可以在Chrome浏览器中传递Windows凭据? 先感谢您!

等待页面加载

我正在尝试创建一个等待页面加载javascript ,但我遇到了错误。 可能我没有正确使用该方法。 public static void WaitForLoad(this IWebDriver driver, int timeoutSec = 15) { WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, timeoutSec)); wait.Until(wd => wd.ExecuteJavaScript(“return document.readyState”) == “complete”); } 错误是: The type arguments for method ‘WebdriverExtensions.ExecuteJavaScript(IWerbDriver,string,params object[]’ cannot be inferred from the usage.Try specifying the type arguments explicity)

使用Selenium使用Webdriver的Timeout的最佳方法是什么?

我遇到了一个问题。 我的网页有一个DropDownList控件。 一旦DropDownList值改变(通过选择不同的值),页面将刷新并呈现内容。 然后我必须使用Thread.Sleep(2000); 在它和FindElement之前。 我的问题:等待页面加载的最佳方法是什么? 我的代码中有很多Thread.Sleep(2000)实例,我开始认为这不是解决问题的最佳方法。 这是我的代码: [TestInitialize()] public void Setup() { if (BaseIntegrationTest.browserType.Equals(BaseIntegrationTest.IE)) { driver = new InternetExplorerDriver(); } else if (BaseIntegrationTest.browserType.Equals(BaseIntegrationTest.CHROME)) { //driver = new ChromeDriver(); } else if (BaseIntegrationTest.browserType.Equals(BaseIntegrationTest.FIREFOX)) { driver = new FirefoxDriver(); } } 第二部分: [TestMethod] public void testVerifyData() { // ………………. // ………………. driver.FindElement(By.XPath(“//*[@id=’ctl00_NavigationControl1_lnke’]”)).Click(); Thread.Sleep(2000); //select from the […]

无法在Selenium中启动Chrome驱动程序

我总是能够在本地启动chromedriver服务器,但之后我尝试远程执行此操作,从那时起我无法启动它。 我重新安装了chrome以及chrome驱动程序,但似乎没有解决这个问题。 即使我给出了我的驱动程序的路径它也不会启动。 using OpenQA.Selenium; using OpenQA.Selenium.Support; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.IE; using OpenQA.Selenium.Chrome; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using OpenQA.Selenium.Safari; using OpenQA.Selenium.Interactions; namespace TestWebDriver { class Program { static void Main(string[] args) { var driver = new ChromeDriver(@”C:\Users\laurens.putseys\Documents\Visual Studio 2015\Projects\TestWebDriver\packages\Selenium.WebDriver.ChromeDriver.2.21.0.0\driver\”); driver.Url = “http://google.be”; Console.ReadLine(); driver.Quit(); } } } 我得到的错误如下: An […]

如何使用Selenium将样式属性设置为元素?

driver.SwitchTo().Frame(“contentFrame”); IWebElement str = driver.FindElement(By.XPath(“//*[@id=’dvCustomDateRange’]”)); 我需要从style =“display:none;”更改style属性 to style =“display:block;”。 这是元素: 任何想法如何使用Selenium这样做? 我尝试使用getAttribute和getCssValue方法来更改值但没有结果。

在selenium / webdriver c#中循环遍历多个moveToElement

我试图通过web元素点击鼠标内的所有这些嵌套链接。 第一次迭代起作用,但在此之后停止。 我试过添加Thread.Sleep(xxxx); 但这也不起作用。 这是我的方法: public static bool TestFindAssets() { bool result = false; Actions action = new Actions(driver); var findAssetsClick = driver.FindElement(By.XPath(“/html/body/div/header/nav/ul/li[3]/a”)); var home = driver.FindElement(By.LinkText(“Home”)); try { for (int i = 1; i < 13; i++) { action.MoveToElement(findAssetsClick).Perform(); //Find Assets Link action.MoveToElement(driver.FindElement(By.XPath("xpath"))).Perform(); //By Type Link action.MoveToElement(driver.FindElement(By.XPath("otherPath"+i))).Click().Build().Perform(); //list of links } result = true; […]