Tag: selenium

Selenium:找到基本url

我在不同的机器上使用Selenium来自动测试MVC Web应用程序。 我的问题是我无法获得每台机器的基本URL。 我可以使用以下代码获取当前url: IWebDriver driver = new FirefoxDriver(); string currentUrl = driver.Url; 但是,当我需要导航到不同的页面时,这无济于事。 理想情况下,我可以使用以下内容导航到不同的页面: driver.Navigate().GoToUrl(baseUrl+ “/Feedback”); driver.Navigate().GoToUrl(baseUrl+ “/Home”); 我使用的可能解决方法是: string baseUrl = currentUrl.Remove(22); //remove everything from the current url but the base url driver.Navigate().GoToUrl(baseUrl+ “/Feedback”); 有没有更好的方法可以做到这一点?

Selenium C#打开新标签CTRL + T不使用CHROME

static void Main() { IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl(“http://google.com”); IWebElement body = driver.FindElement(By.TagName(“body”)); body.SendKeys(Keys.Control + “t”); } 这是我试图用来打开一个新选项卡而不能正常运行的代码,我没有得到任何错误,驱动程序打开谷歌,这就是所有….我已经搜索了很多,发现很多教程甚至video人们使用完全相同的代码,它适用于他们,但对我来说它没有,我无法弄清楚… 我尝试将Keys.Shift +“t”发送到搜索字段并且它可以工作,它在字段中写入大写字母T. 我也试过了 Actions act = new Actions(driver); act.KeyDown(Keys.Control).SendKeys(“t”).Perform(); 它仍然无法正常工作,但如果我将Keys.Control更改为Keys.Shift它写入,似乎没有任何涉及Keys.Control工作! 编辑:我尝试使用IE驱动程序运行代码并在那里工作,它会打开新选项卡,但它不会在Chrome上打开新选项卡?

使用Selenium以不同的用户身份运行Internet Explorer

我想用Selenium作为不同的用户启动单个Internet Explorer实例。 我提到了以下post,但没有到达任何地方。 如何以特定域用户身份运行Internet Explorer Selenium测试? 你能指出我如何实现它的正确方向吗?

无法使用c#在selenium中生成Extent报告(版本3.1.3)

我是C#的新手,我正在尝试使用ExtentReports生成报告(使用版本:3.13)。 任何帮助都将非常感谢谢谢。 我收到以下错误:消息:System.InvalidOperationException:没有记者被启动。 Atleast 1记者必须开始创建测试。 这是我的代码:` using AventStack.ExtentReports; using AventStack.ExtentReports.Reporter; using NUnit.Framework; using NUnit.Framework.Interfaces; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AutomationReports { class ReportsGenerationClass { protected ExtentReports _extent; protected ExtentTest _test; [OneTimeSetUp] protected void Setup() { var dir = TestContext.CurrentContext.TestDirectory + “\\”; var fileName = this.GetType().ToString() + “.html”; var htmlReporter […]

Selenium Webdriver c#无需等待页面加载

我有以下情况: 我想导航到一个页面。 然后在出现时立即单击按钮(不等待页面加载)。 我不想等待初始页面加载,因为它需要很长时间。 我的程序目前一直停滞,直到页面加载,然后单击按钮。 我基本上想要导航到链接,然后没有等待页面并继续我的代码。 无论如何围绕这个?

使用selenium从页面保存图像

我正在使用Selenium和Google Chrome驱动程序以编程方式打开页面。 在每个页面上都有一个动态生成的图像,我想下载它。 目前,我正在等待页面完成加载,然后我抓取图像URL并使用System.Net.WebClient下载它。 这工作正常,除了我下载图像两次 – 一次在浏览器中,一次使用WebClient。 问题是每个图像大约是15MB,下载两次快速加起来。 那么 – 是否可以直接从谷歌浏览器中获取图像?

Facebook用Selenium登录C#

我一直在玩Selenium C#框架并试图登录facebook,但没有运气。 这就是我到目前为止(基于这篇文章: 使用Selenium测试Facebook Connect应用程序? )。 我不能让它工作。 ISelenium sel = new DefaultSelenium(“localhost”, 4444, “*chrome”, “http://facebook.com”); public void LoginWithEmailAndPassword(string email, string pass) { sel.Start(); sel.Open(“http://www.facebook.com”); sel.ClickAt(“//img[\\@alt=’Facebook’]”, “User clicks on Facebook Login”); sel.WaitForPopUp(“”, “3000”); sel.SelectPopUp(“”); sel.Type(“email”, email); sel.Type(“pass”, pass); sel.KeyPress(“pass”, “\\13”); sel.SelectWindow(“null”); } 因此,如果有人可以为我提供一些如何执行此操作的示例代码,或指导我朝着正确的方向发展,那么我们将不胜感激。 解决 通过使用Firefox Selenium插件的记录function,我获得了id和我需要的function才能使它工作。 登录按钮似乎需要XPath定义,我也从Selenium IDE获得。 ISelenium sel = new DefaultSelenium(“localhost”, 4444, “*chrome”, “http://facebook.com”); […]

无法使用Selenium WebDriver在Chrome中加载默认配置文件

我正在使用Selenium WebDriver在需要http身份validation的页面上执行某些操作。 我已经登录了我的默认个人资料。 但是seleniumchromedriver将自动使用每个用途的新配置文件,因此我无法通过身份validation阶段。 因此,我想在Selenium WebDriver for Chrome上使用我的默认配置文件(使用帐户登录)。 即使我使用下面的代码,默认配置文件似乎也没有加载到Chrome中 ChromeOptions options = new ChromeOptions(); options.AddArguments(“user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data/Default”); IWebDriver driver = new ChromeDriver(@”C:\Users\Lawrence\Desktop\selenium-dotnet-2.33.0\net40″,options); 有帮助吗? =)

使用C#按Selenium RC中的Enter键

如何使用C#使用Selenium RC按Enter键? 我正在使用Selenium使用SearchBox 。 我必须在其中键入一些名称,我必须按Enter键进行搜索。 没有“ Submit按钮。 所以,我必须使用回车 。 我试过这样的事 selenium.KeyPress(“quicksearchtextcriteria”, “13”); 但是不起作用。 请帮忙。 注意:我收集了一些可能的方法来执行此操作。 看到这里: 在selenium中按回车键

C#Selenium webdriver JavaScript错误记录

我正在使用C#测试Selenium webdriver。 如何记录我的测试中可能发生的所有JavaScript错误?