Tag: selenium webdriver

使用Selenium突出显示文本

我有一个上下文相关菜单,需要高亮显示文本才能使其正常工作。 但是,我在使用Selenium选择文本时遇到问题。 我首先找到我正在寻找的WebElement,然后尝试使用不同的鼠标事件与它进行交互。 当我试图选择部分文本时,除了将标记放在字符串的末尾之外,它似乎没有做任何其他事情。 这是我的文本框的样子: 这就是我需要它看起来的样子,换句话说,我需要Selenium选择的东西(只是为了说明的目的手动完成它: 这与我在代码中尝试做的一致: public static async Task HighlightElementByCssSelector(this RemoteWebDriver @this, string cssSelector, TimeSpan? timeout = null, TimeSpan? interval = null) { var element = await @this.FindElementByCssSelectorAsync(“.testmarker-registryentryedit .testmarker-title-field”); Actions action = new Actions(@this).MoveToElement(element).ClickAndHold(element).MoveByOffset(10,0).Release(); action.Build().Perform(); } 在这种情况下,@ this表示驱动程序,而FindElementByCssSelectorAsync是“包装器框架”的一部分。 我尝试过不同的MoveToElement,DragAndDrop,ClickAndHold等组合,但我无法让它工作。 关于这里可能有什么问题的任何指示?

在Azure Web App上运行Selenium

我有一个Azure Web应用程序,当我在控制器上调用Action时,我想用它来屏幕抓取网站,就像这样。 var driver = new PhantomJSDriver(); driver.Url = “http://url.com”; driver.Navigate(); var source = driver.PageSource; var pathElement = driver.FindElementByXPath(“//table[@class=’someclassname’]”); string innerHtml = “”; IJavaScriptExecutor js = driver as IJavaScriptExecutor; if (js != null) { innerHtml = (string)js.ExecuteScript(“return arguments[0].innerHTML;”, pathElement); } return innerHtml; 这在本地工作正常,但是当我上传到我的Azure Web App时,我收到此错误 无法在http:// localhost:51169 /上启动驱动程序服务 我认为这与防火墙有关,因为我需要在应用程序第一次运行时在防火墙设置中批准PhantomJS。 我的问题是如何在Azure中部署这个工作? 它是否可能,或者我是否需要将其配置为unit testing并在Visual Studio中运行?

如何让webDriver等待页面加载(C#Selenium项目)

我在C#开始了一个Selenium项目。 尝试等待页面完成加载,然后才进行下一步操作。 我的代码如下所示: loginPage.GoToLoginPage(); loginPage.LoginAs(TestCase.Username, TestCase.Password); loginPage.SelectRole(TestCase.Orgunit); loginPage.AcceptRole(); 在loginPage.SelectRole(TestCase.Orgunit)中: RoleHierachyLabel = CommonsBasePage.Driver.FindElement(By.XPath(“//span[contains(text(), ” + role + “)]”)); RoleHierachyLabel.Click(); RoleLoginButton.Click(); 我搜索元素RoleHierachyLabel。 我一直在尝试使用多种方式等待页面加载或搜索允许一些超时的元素属性: 1. _browserInstance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5)); 2. public static bool WaitUntilElementIsPresent(RemoteWebDriver driver, By by, int timeout = 5) { for (var i = 0; i < timeout; i++) { if (driver.ElementExists(by)) return true; } return false; } 你会如何解决这个障碍?

Selenium webdriver选择新窗口c#

尝试在c#中使用selenium webdriver编写一些测试用例,并且有一个我不确定如何解决的场景 用户场景正在搜索患者的表格,选择患者然后打开一个新窗口,然后在窗口上断言各种项目 我的问题是我无法选择新窗口来断言任何东西,它不是一个弹出窗口,它是一个全新的浏览器窗口,但它没有窗口标题/名称来识别它,我怎么能够将驱动程序焦点切换到此窗口? 提前致谢

无法在45000内启动套接字

我正在使用FF版本19 它一切正常,直到昨天,突然今天早上我开始得到这个错误,我有与之前运行的相同的确切代码,没有任何改变 错误信息: Test ‘M:.TestCases.12’ failed: Failed to start up socket within 45000 OpenQA.Selenium.WebDriverException: Failed to start up socket within 45000 at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.ConnectToBrowser(Int64 timeToWaitInMilliSeconds) at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Start() at OpenQA.Selenium.Firefox.FirefoxDriver.StartClient() at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxBinary binary, FirefoxProfile profile, TimeSpan commandTimeout) at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxBinary binary, FirefoxProfile profile) at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxProfile profile) 0 passed, 1 failed, 0 skipped, took […]

隐藏/沉默ChromeDriver窗口

当我启动Selenium的网络驱动程序(Chromedriver)时。 控制台窗口(chromedriver.exe)运行并打开chrome。 我需要知道如何隐藏那些像静音模式,因为当太多打开时我会变得混乱。 我正在使用C#。

如何将Appium与C#集成?

我无法找到一个post,我可以用C#中的appium自动进行移动测试。 我在specflow中编写了我的网站自动化代码。 我可以重复使用吗?

使用Selenium在现有浏览器会话中打开一个新选项卡

我在C#下面的当前代码打开一个窗口,然后在单击按钮后导航到指定的URL。 protected void onboardButton_Click(object sender, EventArgs e) { IWebDriver driver = new ChromeDriver(); driver.FindElement(By.CssSelector(“body”)).SendKeys(Keys.Control + “t”); driver.Navigate().GoToUrl(“http://www.google.com”) } 但我计划导航到的网站有单点登录 。 如何在现有浏览器会话中打开新选项卡并从那里导航? 上面的代码似乎不起作用。 太感谢了!

在OpenQA.Selenium(C#)中找不到WebDriverWait类

(从Java-Selenium迁移到C#-Selenium) 当使用Selenium和C#搜索显式等待时 ,我发现了几个代码类似于Java-Counterpart的post: 例如这里 : WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0,0,5)); wait.Until(By.Id(“login”)); 或者在这里 : WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“locator”))); WebDriverWait来自OpenQA.Selenium.Support.UI命名空间,并且位于一个名为Selenium WebDriver支持类的单独包中 但: 当我尝试在Visual Studio中编写代码(通过NuGet获取Selenium包)时,在我的代码中使用WebDriverWait将提示消息: 找不到类型或命名空间名称’WebDriverWait’(您是否缺少using指令或程序集引用?) 即使我通过包括Selenium参考 using OpenQA.Selenium; 在查找WebDriverWait的文档时,您会发现应该有一个名为的命名空间 OpenQA.Selenium.Support.UI 但我无法通过代码中的“使用”访问它。 为什么会这样? 我在哪里可以找到WebDriverWait类?

如何避免Selenium上的MouseOver Click()

在我的一个Selenium测试用例中,我遇到了一个问题,即我不想拥有MouseOver效果。 这就是我做的: 点击“登录”按钮(页面右上角) 等待页面加载 单击搜索结果中的“购买”按钮(页面中间右侧)。 问题是,在“登录”和“购买”之间的中间有一个带有MouseOver效果的“购物篮”链接。 因此,当我在“登录”按钮上调用Click()并随后在“购买”按钮上调用时,我会触发MouseOver,这会打开购物车的小预览,其中隐藏了“购买”按钮。 这适用于Firefox和MSIE。 在Chrome中,我没有这种效果。 有人在想吗?