Tag: selenium webdriver

Selenium IE WebDriver:NoSuchElementException

我正在尝试使用Selenium Internet Explorer WebDriver,但是一旦我尝试在加载的页面中找到一个元素,它就会一直抛出exception。 我正在使用在Windows 8.1 x64计算机上运行的Selenium客户端和版本2.44,Internet Explorer 11(我尝试过32位和64位版本)的.NET实现。 这是我正在使用的C#测试代码: IWebDriver driver = new InternetExplorerDriver(); driver.Navigate().GoToUrl(“http://mytesturl.com”); const string name = “Test”; IWebElement nameElement = driver.FindElement(By.Name(“name”)); nameElement.SendKeys(name); //… 这是我正在运行测试的网页: TestSelenium <form action="” method=”post”> Insert name: Submit 一旦到达driver.FindElement(By.Name(“name”))调用,就会引发exception。 在此之前,执行按预期工作(在实例化webdriver时启动IE并正确导航到URL)。 这是我得到的例外: OpenQA.Selenium.NoSuchElementException : Unable to find element with name == name en OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) en OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 […]

按Selenium Webdriver包含的文本选择元素

我已经开始使用Selenium Webdriver了,我直接打了一个问题,涉及我试图选择/点击的按钮都没有ID并且共享同一个类。 所以我想知道如何通过它们包含的独特文本来选择它们。 我可能想用css选择器,但我不确定如何告诉它寻找特定的文本来选择元素。 我现在拥有的是: using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using OpenQA.Selenium.Internal; namespace SeleniumTest1.Methods { public class HomePage { private readonly IWebDriver _browser; public HomePage(IWebDriver browser) { _browser = browser; } public IWebElement SearchBox() { return _browser.FindElement(By.Id(“searchBox”)); } public void ImageButton() { _browser.FindElement(By.CssSelector(“a”)).Click(); } } } […]

如何使用C#使用Selenium WebDriver实例化InternetExplorerDriver

new InternetExplorerDriver(); 但我可以看到exception如下: OpenQA.Selenium.DriverServiceNotFoundException was unhandled by user code HResult=-2146233088 Message=The IEDriverServer.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://code.google.com/p/selenium/downloads/list. Source=WebDriver StackTrace: at OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String executableName, Uri downloadUrl) at OpenQA.Selenium.IE.InternetExplorerDriverService.CreateDefaultService() at OpenQA.Selenium.IE.InternetExplorerDriver..ctor(InternetExplorerOptions options) at OpenQA.Selenium.IE.InternetExplorerDriver..ctor() at Accelrys.CommonTestFramework.WebActions.WebActionLibrary.CreateSeleniumDriver()

在新标签页中打开链接selenium c#

我正在编写一个程序来运行我网站上列出的video用于测试目的,这里我需要的是在同一个浏览器窗口的不同选项卡中运行video。 我在List中有一百个videourlvideoLinks = getVideoUrls(); 现在我需要的是一次执行这些video5。 ChromeDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl(“https://www.withoutabox.com” + videoLink); 如果我采用上述方式,那么对于所有video,我将不得不创建一个新的ChromeDriver对象。 我想使用单个chrome浏览器对象。 我试过这个 IWebElement body = driver.FindElement(By.TagName(“body”)); body.SendKeys(Keys.Control + “t”); 它只会添加一个新标签,但不会在那里打开链接。 请让我知道如何解决它。 我用谷歌搜索但找不到我的解决方案,所以想要寻求帮助。

CodedUI – Chrome浏览器中的Windows身份validation

我正在使用“Cross Browser Selenium Components”插件在Chrome浏览器中运行codedui测试。 当我启动我的Web应用程序时,它需要Windows身份validation才能登录到该网站。 如何在编码的UI中传递用户名和密码以及URL? Webdriver等效代码是: baseUrl =“http://”+ username +“:”+ password +“@”+ url; driver.get(baseUrl +“/”); 但是在codedui中,当我执行下面的代码时,会弹出身份validation窗口,但控件没有通过browser.NavigateToURL ,因此我无法提供用户名和密码。 BrowserWindow.CurrentBrowser = “chrome”; string URL = “http://servername:portnumber/index.jsp”; BrowserWindow browser = BrowserWindow.Launch(); browser.NavigateToUrl(new Uri(URL)); 任何帮助将非常感谢请。

for循环“索引超出范围”c#webdriver

我从这个循环得到“索引超出范围”。 但我需要使用循环创建的新元素,我该怎么做? 请帮助解决问题 int linkCount = driver.FindElements(By.CssSelector(“a[href]”)).Count; string[] links = new string[linkCount]; for (int i = 0; i < linkCount; i++) { List linksToClick = driver.FindElements(By.CssSelector(“a[href]”)).ToList(); links[i] = linksToClick[i].GetAttribute(“href”); }

Selenium Webdriver – 如何为Firefox设置代理以“自动检测”

我的脚本在chrome和IE上运行正常,但由于firefox为其代理设置设置了“manual”,因此无法在firefox上启动。 如何将其设置为“自动检测”? C#中的源代码请。 谢谢

拖放被执行但它没有被执行 – webdriver

我已经尝试了这两个代码,它被执行但是动作没有执行,任何人都可以告诉我为什么? //Type one approach Actions action = new Actions(Browser.Driver); IWebElement sourceElement = Browser.Driver.FindElement(By.XPath(Filexpath)); IWebElement targetElement = Browser.Driver.FindElement(By.XPath(NewXpath)); //Type two approach Actions Sourcebuilder = new Actions(Browser.Driver); Actions SourceAction = Sourcebuilder.ClickAndHold(sourceElement); Sourcebuilder.Build(); SourceAction.Perform(); /// move and drop Actions builder = new Actions(Browser.Driver); Actions action = builder.MoveToElement(targetElement); builder.Release(targetElement); builder.Build(); action.Perform(); 提前致谢

如何从selenium中的href链接获取属性值

我试图从“a href”属性获取链接 Download 我在做什么: ReadOnlyCollection lists1 = driver.FindElements(By.ClassName(“dl_link”)); string s = lists1[0].GetAttribute(“a href”); 我正在获取类“dl_link 1”的元素,但我无法得到它的链接,字符串为空?

Xunit为每个新测试创建Test类的新实例(使用WebDriver和C#)

有没有办法在使用Xunit的Webdriver(Selenium)在同一浏览器中运行多个测试,目前xunit为每个新测试启动新浏览器,下面是示例代码 public class Class1 { private FirefoxDriver driver; public Class1() { driver = new FirefoxDriver(); } [Fact] public void Test() { driver.Navigate().GoToUrl(“http://google.com”); driver.FindElementById(“gbqfq”).SendKeys(“Testing”); } [Fact] public void Test2() { driver.Navigate().GoToUrl(“http://google.com”); driver.FindElementById(“gbqfq”).SendKeys(“Testing again”); } }