Tag: selenium

如何将Wait.Until与Selenium C#一起用于现有元素

我正在寻找一种在selenium(C#)中使用wait.until的方法,但是对于现有元素。 那样: [FindsBy(How = How.Id, Using = “SomeID”)] public IWebElement SearchButton { get; set; } 现在,我想将wait.until用于上面的元素。 我能以任何方式做到这一点吗? 谢谢Yaniv

想要检索给定WebElement的Xpath

使用Selenium WebDriver,我有一个页面中所有Web元素的列表。 我想编写一个函数,它将返回传递元素的XPath字符串。 Call for Function将如下所示: – String XpathOfElement = myWebDriver.getXpath(My_Web_Element) 提示 : – 我认为我们可以使用javascript(使用JavaScriptExecuter)。 但不熟悉javascript。

Selenium Grid Hub和节点问题

HELPPPP PLEASSEE! 现在我已经使用以下内容设置了selenium网格: -Machine A上有一个集线器和节点(集线器在同一台机器上的节点)。 -Machine B(与集线器不同的机器不一样),上面有2个节点。 因此,我现在有一个集线器和3个节点:1在集线器机器(机器A)上充当节点,2在另一个物理节点机器(机器B)上。 因此,通过此设置,我可以并行AFAIK运行3个测试用例。 我会帮助我所做的一切。 集线器的setup命令: java -jar selenium-server-standalone-3.0.0-beta2.jar -role hub -port 4445 (我更改了默认端口号) 节点的setup命令: java -jar -Dwebdriver.ie.driver =“C:\ Libraries \ IEDriverServer.exe”-Dwebdriver.chrome.driver =“C:\ Libraries \ chromedriver.exe”selenium-server-standalone-3.0.0-beta2.jar -role webdriver -hub http:// HubIP:4445 / grid / register -port 4453 然后是C#中的代码用于设置和测试: using System; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Chrome; using OpenQA.Selenium.Safari; using OpenQA.Selenium.Edge; […]

使用Selenium代理

在过去的两天里,我一直在尝试使用Selenium的代理,但这不是问题。 问题是代理是私有的意味着它需要身份validation才能使用它(用户名和密码),但我无法弄清楚如何做到这一点。 我正在使用Firefox驱动程序,其配置文件如下: FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.SetPreference(“network.proxy.type”, 1); firefoxProfile.SetPreference(“network.proxy.http”, “23.95.115.87”); firefoxProfile.SetPreference(“network.proxy.http_port”, 80); var driver = new FirefoxDriver(firefoxProfile); driver.Navigate().GoToUrl(“http://ipchicken.com”); 我想它会询问我的用户名和密码(在对话框中)但没有任何反应,它只是导航到网页,并显示我自己的IP。 我找不到任何真的这个,有什么帮助吗? 非常感谢。

无法与最新版本的Selenium 3.12在Chrome浏览器(版本67.0.3396.87)中与WebElements交互

我正在尝试登录网页并希望传递userId和密码。它没有传递用户ID /密码而页面被停止。获取以下exception – “{对远程WebDriver服务器的URL请求http:// localhost:6905 / session / 4e1158e787cbb6d6a16e5352a290cc89 / element / 0.5806346454853202-1 / 60秒后单击超时。”}“使用chromedriver版本2.40.0,Chrome浏览器版本是67.0.3396.87和Selenium webdriver版本是3.12 还注意到与IE11相同的问题。 请提供有关此的任何帮助/建议。 IWebDriver IeDriver; ChromeOptions options = new ChromeOptions(); options.AddArgument(“disable-infobars”); options.AddAdditionalCapability(“useAutomationExtension”, false); options.AddArgument(“no-sandbox”); IeDriver = new ChromeDriver(options); IeDriver.Navigate().GoToUrl(“https://in.linkedin.com/”); Thread.Sleep(5000); IeDriver.FindElement(By.Id(“login-email”)).Click(); 从Click()方法抛出exception。 “{对URL远程WebDriver服务器的URL请求http:// localhost:6905 / session / 4e1158e787cbb6d6a16e5352a290cc89 / element / 0.5806346454853202-1 / 60秒后单击超时。”}“ StackTrace:OpenQA.Selenium.WebDriverException HResult = 0x80131500 Message =对远程WebDriver服务器的URL请求http:// […]

Selenium Grid 2 – 远程Webdriver未在FireFox中设置用户代理首选项

我在Windows机器上使用selenium server 2.28。 我已经设置了集线器和节点。 我正在使用.net来编写我的测试用例。 我使用以下代码使用自定义FireFox(17.0.1)配置文件与用户代理更改(到iPhone)。 FirefoxProfileManager profileManager = new FirefoxProfileManager(); FirefoxProfile profile = profileManager.GetProfile(FireFox_Profile_Name); profile.SetPreference(“general.useragent.override”, _sUserAgent); DesiredCapabilities capability = DesiredCapabilities.Firefox(); capability.SetCapability(FirefoxDriver.ProfileCapabilityName, profile); 我正在实例化一个这样的RemoteWebDriver实例: driver = new RemoteWebDriver(new Uri(“hub_uri”), capability); 当我在节点机器上检查firefox实例中的about:config时,我根本看不到general.useragent.override首选项。 如果我使用: driver = new FirefoxDriver(profile); 首选项设置正确。 我错过了什么吗?

未处理的exception:system.typeInitializationException

我使用selenium webdriver导航到网站并发送密钥。 它在开发环境/计算机上工作正常。 但是当我试图通过不同的计算机运行时,我收到错误。 namespace McaidWebToolImport { class Program { static void Main(string[] args) { Console.WriteLine(“Enter the batch number: “); string batchnumber = Console.ReadLine(); if (batchnumber != “”) { IWebDriver driver1 = new InternetExplorerDriver(@”C:\IEDriverServer\”); driver1.Navigate().GoToUrl(“http://website.com/webtool/physPop.asp?b=” + batchnumber); System.Threading.Thread.Sleep(2000); driver1.Quit(); } else { Console.WriteLine(“Re-run the application with valid batch number”); Console.WriteLine(“\n\nPress Esacpe key (Esc) to exit”); […]

Selenium框架页面对象模型和页面导航

我正在学习如何使用Selenium为Web应用程序创建框架。 我现在正在学习如何使用页面导航创建页面对象模型。 我目前正在播放的video展示了如何执行此操作,但video末尾的代码无效。 他试图使用类的返回类型初始化该类中的所有对象,但他没有这样做,因为他使用了非参数化的构造函数。 那么有没有办法在使用非参数化构造函数时初始化我的页面元素? video位于:http: //youtu.be/IUBwtLG9hbs 在上面的video中,他只是创建了一个简单的测试,将文本“Selenium”输入到谷歌文本框中。 点击搜索。 单击Selenium链接。 然后单击Selenium网页上的“下载”选项卡。 在video结束时,他试图通过在单击按钮或链接后初始化元素来显示如何使用页面导航,从而将您发送到新页面。 此测试的目标是在从Google页面单击Selenium链接后映射Selenium网页的所有元素。 所以他补充说“返回新的SeleniumPageObjects();” 到GoogleHomePageObjects类中的以下方法: public SeleniumPageObjects ClickSelenium() { lnkSelenium.Click(); return new SeleniumPageObjects(); } 然后在Test类的main / test方法中,他添加以下内容以单击Selenium链接,然后返回Selenium页面的所有映射对象: SeleniumPageObjects selPage = page.ClickSelenium(); 然后他在SeleniumPageObjects类中添加了一个构造函数: public SeleniumPageObjects() { } 它抛出NullReferenceException,因为它从未初始化selenium页面对象(请参阅下面的代码,了解如何在不使用返回类型的情况下完成它)。 怎么解决这个问题? 他说要观看第7部分,但是我看了第7部分并且错误的代码从未得到解决。 注意:我已经知道如何在main / test方法中显式初始化页面对象。 例如,将其添加到main / test方法: SeleniumPageObjects selPage = new SeleniumPageObjects(driver); 并初始化SeleniumPageObjects类中的元素: public SeleniumPageObjects(IWebDriver driver) { […]

在C#中使用Selenium IE驱动程序快速发布大量文本(10,000行)

所以我现在正在编写这个脚本,它将使用C#中的Selenium Internet Explorer驱动程序自动完成一个简单,单调的任务。 一切都很好,但是在脚本的某一点上它有点慢,我想知道是否有更快的方法可以做我想要的。 问题在于我必须用大量信息填写文本框。 此文本框有时会填充多达10,000行,其中每行不超过20个字符。 但是,以下方法非常慢…… // process sample file using LINQ query var items = File.ReadAllLines(sampleFile).Select(a => a.Split(‘,’).First()); // Process the items to be what we want to add to the textbox var stringBuilder = new StringBuilder(); foreach (var item in items) { stringBuilder.Append(item + Environment.NewLine); } inputTextBox.SendKeys(stringBuilder.ToString()); 有没有只是将文本框的值设置为我想要的? 或者这是一个瓶颈? 感谢您的时间和耐心!

显式等待Selenium Webdriver手中的元素

我在C#上使用selenium webdriver,我正在使用页面对象模块。 现在我需要在显式等待中使用语法,因为我已经掌握了webelement。 [FindsBy(How = How.Id, Using = “Passwd”)] public IWebElement Password {get;set;} [FindsBy(How = How.Id, Using = “signIn”)] public IWebElement Signin { get; set; } 我需要等到找到Element Password。 在使用这个模块之前我使用的是: WebDriverWait wait = new WebDriverWait(driver.driver, TimeSpan.FromSeconds(Time)); wait.Until(ExpectedConditions.ElementExists(by)); 现在我需要手中使用Element。