Tag: selenium

在C#中使用Selenium WebDriver中的特定Firefox配置文件

我正在尝试使用我已经为seflium 2设置的firefox配置文件,但没有C#的文档。 我试过的代码如下: FirefoxProfileManager profileManager = new FirefoxProfileManager(); FirefoxProfile profile = profileManager.GetProfile(profileName); driver = new FirefoxDriver(profile); 我在Java中看到的代码使用的是使用ProfilesIni而不是FirefoxProfileManager的代码,但这在C#中不可用。 以这种方式设置驱动程序时,使用的selenium配置文件具有所有默认设置,而不是我试图指向的配置文件中指定的设置。 我不确定我是否使用正确的方法来检索配置文件,但如果有人使用Selenium 2和C#,任何信息都会有所帮助。

geckodriver.exe不在当前目录或路径变量中,Selenium 2.53.1 + Firefox 48 + Selenium 3 Beta

看到很多关于Selenium 2.53.1和Firefox 47.0.1的问题,但没有关于Selenium 3 Beta版本的问题。 我正在尝试使用新的gecko / marionette Firefox webdrivers,但即使我有驱动程序位置; 我的环境路径,Firefox在程序中安装文件夹,并在系统环境中给出驱动器位置,它仍然无法正常工作。 错误: geckodriver.exe不存在于当前目录或PATH环境变量的目录中。 该驱动程序可以从https://github.com/mozilla/geckodriver/releases下载。 使用: Selenium 2.53.1服务器 Firefox 48 Selenium 3 Beta DLLs 窗口10 示例代码1 using OpenQA.Selenium.Firefox; public static class FirefoxInitialise { public static IWebDriver Driver {get; set;} Driver = new FirefoxDriver(); } 还尝试了以下内容: using OpenQA.Selenium.Firefox; public static class FirefoxInitialise { public static IWebDriver Driver […]

如何在Selenium C#中使用PageFactory / FindsBy初始化SelectElements?

我正在使用PageFactory在Selenium WebDriver中为C#构建一个页面对象模型。 不幸的是,我发现FindsByAttribute不会初始化SelectElement (HTML 标签/下拉菜单)。 到目前为止,我已经碰巧或提出了一些想法来解决它,但它们都不是理想的: PageFactory和FindsByAttribute是sealed ,所以我不能通过inheritance它来强迫它。 在每个方法中从IWebElement手动实例化SelectElement是相当混乱和重复的。 它还忽略了PageFactory明显的内置等待并抛出NoSuchElementException除非我每次都添加一个等待 – 这需要在整个地方重复定位器,从而击败(部分)POM的目的。 使用SelectElement属性包装每个IWebElement属性不那么混乱,但仍然具有与上面相同的等待问题。 到目前为止,最好的选择是#3,并为SelectElement编写一个包装器,它只是为每个方法添加一个等待。 虽然这个解决方案可行 ,但它会大量增加每个页面的代码,而不是这个(假设的)漂亮的代码: [FindsBy(How = How.Id, Using = “MonthDropdown”)] public SelectElement MonthDropdown; 我坚持使用包装器包装(我宁愿避免使用),并且: [FindsBy(How = How.Id, Using = “MonthDropdown”)] private IWebElement _monthDropdown; public Selector MonthDropdown { get { return new Selector(MonthDropdown, Wait); } } 使用Selector作为SelectElement包装器,它还必须接收IWait以便它可以等待,并在每次访问时实例化一个新的Selector 。 有更好的方法吗? 编辑:瞌睡错误的访问修饰符。 固定。 谢谢,@ JimEvans。

如何使用WebDriver(Selenium 2)检查dom是否有类?

我对Selenium很新,所以如果这是一个愚蠢的问题,我道歉。 我已经成功地将IntelliJ(Play!框架)与Selenium连接起来,并使用firefoxDrivers创建了一些测试。 我正在尝试检查页面是否已经过正确validation。 长话短说,我正在选择这样一个元素: WebElement smallDecel = firefoxDriver.findElement(By.cssSelector(“#configTable tr:nth-child(2) td .playerDecelInput”)); 我做了一些进一步的操作(清除并更改值,提交’表单’),然后我想检查输入所在的TD是否给了另一个类。 所以,问题是 – 是否有一种简单的技术可以用来确定WebElement / DOM是否指定了类?

无法使用Selenium Webdriver打开Chrome浏览器。 管理员禁用加载解压缩的扩展名

我使用Selenium Webdriver,C#,Visual Studio和Chrome浏览器自动化我的应用程序。 当selenium试图打开Chrome浏览器时,我正在低于弹出窗口。 Failed to load extension from:C:\Users\VARA~1.PAK\AppData\Local\Temp\scoped_dir6712_14913\internal. Loading of unpacked extensions is disabled by the administrator. 点击弹出窗口的确定按钮后,Chrome就会成功打开,但由于以下错误,我的测试失败了。 Test Name: _3_EnterDetailsAndSelectAnAddress_John Test FullName: Veolia.BrentGWP.UserStories.Features.BrentGWPFeature._3_EnterDetailsAndSelectAnAddress_John Test Source: : line 2147483647 Test Outcome: Failed Test Duration: 0:00:47.8059413 Result Message: Test method Veolia.BrentGWP.UserStories.Features.BrentGWPFeature._3_EnterDetailsAndSelectAnAddress_John threw exception: System.InvalidOperationException: unknown error: cannot get automation extension from unknown error: page could […]

WebDriver – 元素不可点击Chrome

我有以下问题。 我在Firefox和Chrome上运行测试。 在Firefox测试运行正确,但在Chrome SauceLabs上给出一条消息: unknown error: Element is not clickable at point (717, 657). Other element would receive the click: … (Session info: chrome=36.0.1985.125) (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.3 x86_64) 我以同样的方式在两个测试中通过唯一的css选择器选择元素: driver.FindElement(By.CssSelector(“button.btn-xs:nth-child(1)”)).Click(); 任何想法在这里有什么问题?

如何在无头模式下启动ChromeDriver

我想尝试无头镀铬,但我遇到了这个问题,我无法在无头模式下启动驱动程序。 我正在关注谷歌文档 。 我错过了什么吗? 代码执行卡在var browser = new ChromeDriver(); 线 这是我的代码: var chromeOptions = new ChromeOptions { BinaryLocation = @”C:\Users\2-as Aukstas\Documents\Visual Studio 2017\Projects\ChromeTest\ChromeTest\bin\Debug\chromedriver.exe”, DebuggerAddress = “localhost:9222” }; chromeOptions.AddArguments(new List() {“headless”, “disable-gpu” }); var browser = new ChromeDriver(chromeOptions); browser.Navigate().GoToUrl(“https://stackoverflow.com/”); Console.WriteLine(browser.FindElement(By.CssSelector(“#h-top-questions”)).Text);

C#Selenium正在保存pdf页面

如何直接在pdf中执行保存此页面? 我知道selenium无法控制chrome对话框……还有另外一种方法吗? 图像: 以pdf格式保存的页面

如何使用Selenium Web驱动程序上传文件/句柄窗口

我正在尝试自动化我必须上传文档的场景,但是当我单击Web应用程序上的“选择文件”按钮后,我无法处理“ 文件上载”窗口。 我正在使用C#语言和Chrome浏览器。

使用selenium Firefox webdriver将 文本清空

我在Windows 7上使用Firefox 21和C#WebDriver 2.33。我很困惑为什么以下测试失败(我只是检查我的配置设置是否正确)。 这在其他浏览器中传递。 [Test] public void FirefoxDriverWorks() { var firefoxDriver = new FirefoxDriver(); TestGoogleStillExists(firefoxDriver); firefoxDriver.Quit(); } public void TestGoogleStillExists(IWebDriver webDriver) { webDriver.Navigate().GoToUrl(“http://www.google.com”); var title = webDriver.FindElement(By.CssSelector(“head title”)); Assert.That(title.Text, Is.EqualTo(“Google”)); }