【C#使用Selenium】教程文章相关的互联网学习教程文章

c# – 在新选项卡中打开的Selenium驱动程序不能像社区共享知识所描述的那样工作【代码】

我知道这是一个矛盾的话题. “正式”驱动程序不支持选项卡,但是许多地方声明新打开的选项卡将通过窗口句柄可用,我们可以使用句柄在选项卡之间切换. (代码示例是C#,但我希望问题中的C#没有什么特别之处)driver.SwitchTo.Window(myHandle);我正在尝试在新标签中打开一个链接.我有成功,浏览器显示新选项卡,但驱动程序的窗口句柄不包含新打开的选项卡,只包含一个原始窗口句柄.这似乎是合乎逻辑的,选项卡不是一个窗口,但是在许多地方它被...

javascript – 如何在C#Selenium中向FirefoxDriverService添加配置文件规范?【代码】

上下文:Azure,C#,ClearScript,Selenium,Firefox 我将Selenium的Firefox符号暴露在ClearScript JavaScript环境中.在以下JavaScript代码中,从C#公开/导出的符号以CS为前缀.// Preamble_LaunchBrowser.js driverService = CSFirefoxDriverService.CreateDefaultService(); driverService.FirefoxBinaryPath = "C:\\Program Files\\Mozilla Firefox\\firefox.exe"; driverService.HideCommandPromptWindow = true; driverService.Supp...

c# – 如何在selenium中获取已经打开的IE浏览器句柄?【代码】

我有一个已经打开的IE浏览器,有一些网址.在此之后,我运行下面的代码将打开另一个IE浏览器.但它在下面的代码中只给了我一个窗口句柄.是否有可能获得以前打开的IE浏览器处理?IWebDriver IEdriver = new InternetExplorerDriver();IReadOnlyCollection<String> browsers = IEdriver.WindowHandles;foreach (String item in browsers){IEdriver.SwitchTo().Window(item);String url = IEdriver.Url;}解决方法:我想这就是你要找的东西:...

c# – Selenium 2 StaleElementReferenceException使用DropDownList和AutoPostBack使用InternetExplorerDriver时【代码】

我正在使用Selenium 2使用InternetExplorerDriver测试asp.net Web表单页面并遇到StaleElementReferenceException.该页面包含一个(自动回发)下拉列表,我从中选择不同的值. 示例代码: 页:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication.WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transition...

如何在C#中用selenium webdriver点击javascript确认对话框【代码】

我正在用C#编写selenium代码来与表单进行交互 这是提交按钮:<input type="submit" value="Submit" onclick="return confirm('Submit?');" class="SubmitButton">这是我单击提交按钮的Selenium代码.IAlert alert = driver.SwitchTo().Alert(); alert.Accept();然而,当我这样做时,没有点击’ok’按钮.相反,对话框消失,表单就像从未点击提交输入一样.我究竟做错了什么?解决方法:我不知道为什么你的代码不起作用(我的版本具体),它对我...

c# – 如何使用Selenium webdriver使用MouseOver测试工具提示文本【代码】

我有一个小行李图标,当鼠标悬停在图标上时,会显示工具提示文本.我想通过在Visual Studio中编写C#代码来测试它. 以下是html中行李图标的显示方式:<div class="icon_png information icon_baggageyes" title="1 piece included in this fare."></div>这是我的代码来测试工具提示:Actions a = new Actions(driver); IWebElement tooTipObject = driver.FindElement(By.XPath("//div[@class='icon_png information icon_baggageyes']...

c# – 如何修复“元素当前不可见”的Selenium元素【代码】

我想点击< a> < div>内的元素.这是html:<div class="cart__checkout cart__checkout--small"><a class="button button--lg button--info button--checkout" title = "Checkout" href = "https://shop.adidas.ae/en/checkout/onepage/"><span> Checkout </span><i class="icon-sprite icon-sprite-arrow-white-right-type-4"></i></a> </div> <button id="update_cart_action" class = "button btn-update" style = "display: none...

如何使用Phantomjs,selenium和c#连接到Tor网络【代码】

我正在尝试使用PhantomJS和Tor在.onion网站上自动化网站.有谁知道如何连接到网络?解决方法:Tor客户端在127.0.0.1:9050创建本地socks代理服务器 因此,您应该启动PhantomJS将其指向该代理:phantomjs --proxy-type=socks5 --proxy=127.0.0.1:9050 script.js

c# – 在具有基类的多个浏览器中运行Selenium测试【代码】

假设我有代码:namespace SeleniumTests {[TestFixture(typeof(FirefoxDriver))][TestFixture(typeof(InternetExplorerDriver))]public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new(){private IWebDriver driver;[SetUp]public void CreateDriver () {this.driver = new TWebDriver();}[Test]public void GoogleTest() {driver.Navigate().GoToUrl("http://www.google.com/");IWebElement qu...

c# – 使用Selenium WebDriver在自定义路径下载文件【代码】

我是selenium的新手,我想在特定的自定义文件夹中下载带有selenium chrome web驱动程序的文件.默认情况下,文件在浏览器指定的下载路径中下载.任何人都建议在C#Selenium中自定义路径下载文件的最佳解决方案.解决方法:希望对您有所帮助!!var chromeOptions = new ChromeOptions();chromeOptions.AddUserProfilePreference("download.default_directory", "Your_Path");chromeOptions.AddUserProfilePreference("intl.accept_languages...

在selenium c#中找不到类型或命名空间SelectElement【代码】

driver.FindElement(By.Id("inputUsername")).SendKeys("aca"); driver.FindElement(By.Id("inputPassword")).SendKeys("123"); driver.FindElement(By.TagName("button")).Click();SelectElement oSelect = new SelectElement(driver.FindElement(By.Id("selectFilterbyUser"))); oSelect.selectByText("Alex");有没有人能解决我上面附带的问题?尝试使用SelectElement,但它显示:The type or namespace `SelectElement` could no...

c# – 如何在后台启动PhantomJS Selenium窗口?【代码】

我在我的应用程序中使用selenium phantomjs,但我想在后台启动我的应用程序,selenium和phantomjs窗口.我该怎么做? 我试过了:PhantomJSOptions options = new PhantomJSOptions(); options.AddAdditionalCapability("start-maximized", false); IWebDriver driver = new PhantomJSDriver(Environment.CurrentDirectory + @"\drivers", options);解决方法: var serviceJs = PhantomJSDriverService.CreateDefaultService(phantomPat...

c# – Selenium:如何通过部分href找到元素?【代码】

工作代码1:Driver.Instance.FindElement( By.XPath("//a[contains(@href,'" + PartialLinkHref + "')]" ));工作代码2:ReadOnlyCollection<IWebElement> linkList = Driver.Instance.FindElements(By.TagName("a")); for (int i = 0; i < linkList.Count ; i++) {if (linkList[1].GetAttribute("href").Contains(PartialLinkHref)){element.SetElement(linkList[i]);return element;break;} }解决方法:初始选择器的问题在于您在选...

Selenium C#Java – WebDriver和IWebDriver有什么区别?

我目前在Java和C#中学习Selenium,使用Selenium IDE导出记录的浏览器交互.我注意到在Java代码中我们使用WebDriver驱动程序;在C#代码中我们使用IWebDriver驱动程序;有什么不同?最佳答案:C#约定是接口以I为前缀,例如IEnumerable,IDisposable. Java没有这样的约定.