Tag: selenium

C#Selenium移动仿真在景观中

我正在使用c#在.Net环境中使用Selenium进行一些移动UI测试。 我能够在纵向模式下使用chrome移动仿真非常成功地进行测试,但我找不到如何将仿真置于横向模式。 我希望能够在测试期间以编程方式旋转,但通过研究,这似乎还不可能。 在纵向模式下工作。 ChromeOptions chromeCapabilities = new ChromeOptions(); chromeCapabilities.EnableMobileEmulation(“Apple iPhone 6″); ChromeDriverService service = ChromeDriverService.CreateDefaultService(@”C:\chromedriver”); IWebDriver driver = new ChromeDriver(service, chromeCapabilities); driver.Navigate().GoToUrl(“www.google.com”); 但是,如何将iPhone模拟放入横向? 我试过这个但它不起作用,浏览器打开没有大小限制 ChromeMobileEmulationDeviceSettings CMEDS = new ChromeMobileEmulationDeviceSettings(); CMEDS.Width = 66; CMEDS.Height = 37; CMEDS.PixelRatio = 1.0; CMEDS.UserAgent = “Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) […]

更改每个文件的下载位置和名称

我正在使用Selenium和Chrome WebDriver进行自动化。 应用程序必须执行一系列需要使用不同名称(数据+报告类型)保存的下载以及与我正在下载的报告类型相匹配的文件夹。 问题是我只能在实例化新驱动程序时设置默认目录 var chromeOptions = new ChromeOptions(); chromeOptions.AddUserProfilePreference(“download.default_directory”, downloadDirectory); chromeOptions.AddUserProfilePreference(“intl.accept_languages”, “nl”); chromeOptions.AddUserProfilePreference(“disable-popup-blocking”, “true”); IWebDriver driver = new ChromeDriver(@”location chromeDriver”, chromeOptions); driver.Navigate().GoToUrl(url); 因此,我无法重命名文件名或选择相应的目录。 有谁知道我怎么能这样做?

FindBy注释用于查找WebElements列表

在java中,我使用这样的代码来获取具有相同标识符的WebElements列表: @FindBy(how = How.CLASS_NAME, using = “name”) private List names; 现在,我正在使用c#而我正在尝试使用以下方法执行相同的操作: [FindsBy(How = How.ClassName, Using = “name”)] private List names; 但是,这给出了例外: System.ArgumentException:类型为“Castle.Proxies.IWrapsElementProxy_1”的对象无法转换为类型’System.Collections.Generic.List`1 [OpenQA.Selenium.IWebElement]’。 我已经尝试过FindAllBy和FindBys,但这些似乎没有效果。 无论如何我还能做到这一点 names = getDriver().findElements(By.ClassNames(“…”)) ?

如何禁用“您确定要离开此页面”提醒吗?

我正在使用c#selenium webdriver。 我想关闭Chrome警告。 例如,禁用您确定要保留此页面警报。 以下代码均无效。 您可以帮助解释代码。 private void Form1_Load(object sender, EventArgs e) { ChromeOptions options = new ChromeOptions(); options.AddArgument(“–disable-notifications”); options.AddArguments(“–disable-extensions”); // to disable extension options.AddArguments(“–disable-notifications”); // to disable notification options.AddArguments(“–disable-application-cache”); // to disable cache options.AddArgument(“–safebrowsing-disable-download-protection”); options.AddArgument(“ignore-certificate-errors”); options.AddArgument(“–disable-popup-blocking”); options.AddArgument(“–disable-gpu”); options.AddArgument(“–incognito”); options.AddUserProfilePreference(“disable-popup-blocking”, “true”); driveri = new ChromeDriver(options); driveri.Navigate().GoToUrl(“http://web.com”); IJavaScriptExecutor js = (IJavaScriptExecutor)driveri; js.ExecuteScript(“window.alert = function() {};”); }

Selenium – 陈旧元素引用:元素未附加到C#中的页面文档

我使用selenium将网站表格中的数据转化为分析。 我必须扫描并获得约1000行的表格。 我知道该页面有Javascript,它会自动更新DOM。 但表中的行数太多,所以当我扫描我的代码时总会抛出exception。 我尝试使用此代码: Boolean breakIt = true; List result = new List(); while (true) { breakIt = true; try { IWebElement baseTable = browser.FindElementById(“column2”); ReadOnlyCollection rowsTable = baseTable.FindElements(By.XPath(“id(‘oTable’)/table/tbody/tr”)); foreach (IWebElement rows in rowsTable) { if (rows.FindElements(By.XPath(“td”)).Count == 10) result.Add(rows); } if (breakIt) { break; } } catch (StaleElementReferenceException ser) { if (ser.Message.Contains(“element is […]

如何在定位元素之前等待加载帧?

我正在等待Selenium在等待另一个元素之前切换更改帧。 即 var wait = new WebDriverWait(driver, 15); wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Id(“frameA”)); var wait2 = new WebDriverWait(driver, 15); // wait for element within frameA to exist wait2.Until(ExpectedConditions.ElementExists(By.Id(“elementA”))); 如果我抛入一个简单的Thread.Sleep(1000); 在第二次等待之前它运行正常,但没有它我得到以下错误: ‘unknown error: unhandled inspector error: {“code”:-32000,”message”:”Cannot find context with specified id”} enter code here 有没有更好的方法等待帧上下文切换完成之后再等待该帧中的元素被填充?

Selenium Wait不等待Element可点击

我有一个动态加载的页面,包含一个按钮。 我正在尝试等待按钮可以使用C#绑定点击selenium。 我有以下代码: WebDriverWait wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(30)); wait.Until(ExpectedConditions.ElementToBeClickable(By.Id(“addInspectionButton”))); var button = Driver.Instance.FindElement(By.Id(“addInspectionButton”)); button.Click(); 这不起作用。 从未触发click事件。 selenium脚本不会抛出exception,提示ID为“addInspectionButton”的元素不存在。 它只是无法点击它。 如果我添加一个Thread.Sleep(3000)在wait语句和我得到按钮元素句柄的行之间它工作。 我在这里没有正确使用ExpectedConditions.ElementToBeClickable吗?

如何在C#中使用Selenium WebDriver获取当前窗口的URL?

在登录时我的应用程序中,它会导航到另一个页面。 现在我需要在selenium C#中使用WebDriver获取新的URL。 我找不到任何function来做到这一点。 我已经尝试过driver.Url , driver.getLocation()和driver.getCurrentUrl() ,但我的C#应用​​程序中没有任何工作。 那么有可能以某种方式得到当前的URL吗? 导航后?

是否可以使用Visual Studio获取集成测试的代码覆盖率数据?

我正在测试ASP.NET应用程序,并希望获得有关我的集成测试运行的产品代码量的代码覆盖率信息。 我们的库已经过检测,符号(pdb)文件可用,但我需要确切知道如何启用Visual Studio来捕获在IIS中执行的代码并返回.coverage文件。 我的集成测试是web api测试和Selenium浏览器测试的混合。 可以这样做吗?

警报处理 – Selenium WebDriver / Selenium RC 2.18.0 – 例外

我的Web应用程序自动化测试软件在IE,Firefox,Chrome和Safari上运行,使用C#和Selenium WebDriver(IE,Firefox,Chrome),Selenium RC(Safari)编写。 我今天升级到版本2.18.0时发生了新的错误。 我看到以下exception: System.InvalidOperationException:存在模式对话框(UnexpectedAlertOpen) 到目前为止,我看到IE,Firefox和Safari都没有抛出此exception。 我查阅了发布文档,但没有发现任何暗示我应采取不同措施接受或取消警报的内容。 这是一个错误,还是有关于警报的新程序?