标签: webdriver

如何让Selenium Web Driver等待元素可访问,而不仅仅是存在?

我正在为Web应用程序编写测试.某些命令会拉出对话框,这些对话框具有可见的控件,但暂时不可用.(它们是灰色的,但是webdriver仍然看到它们可见).

我如何告诉Selenium等待元素实际可访问,而不仅仅是可见?

    try:
        print "about to look for element"
        element = WebDriverWait(driver, 10).until(lambda driver : driver.find_element_by_id("createFolderCreateBtn"))
        print "still looking?"
    finally: print 'yowp'
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的代码,但它在可用之前"看到"了按钮,基本上是在假定的"等待"之后收费.

请注意,我可以在代码中填充十秒钟而不是这样,代码将正常工作,但这是丑陋,不可靠和低效的.但它确实证明问题只是"点击"命令在控制的可用性之前飙升.

python selenium webdriver

28
推荐指数
2
解决办法
5万
查看次数

如何使用selenium webdriver发送cookie?

每当我运行我的测试时,第一步是登录,而不是我想要的页面.如果运行此测试,则经常登录操作需要花费大量时间.

如何通过登录操作?

使用Chrome和Firefox驱动程序,java语言.

java selenium webdriver

28
推荐指数
3
解决办法
6万
查看次数

selenium web驱动程序如何知道新窗口何时打开然后恢复执行

我在使用selenium web驱动程序自动化Web应用程序时遇到了问题.

该网页有一个按钮,单击该按钮可打开一个新窗口.当我使用以下代码时,它会抛出OpenQA.Selenium.NoSuchWindowException: No window found

WebDriver.FindElement(By.Id("id of the button that opens new window")).Click();
//Switch to new window
_WebDriver.SwitchTo().Window("new window name");
//Click on button present on the newly opened window
_WebDriver.FindElement(By.Id("id of button present on newly opened window")).Click();
Run Code Online (Sandbox Code Playgroud)

为解决上述问题,我Thread.Sleep(50000);在按钮单击和SwitchTo语句之间添加.

WebDriver.FindElement(By.Id("id of the button that opens new window")).Click();
Thread.Sleep(50000); //wait
//Switch to new window
_WebDriver.SwitchTo().Window("new window name");
//Click on button present on the newly opened window
_WebDriver.FindElement(By.Id("id of button present on newly opened window")).Click();
Run Code Online (Sandbox Code Playgroud)

它解决了这个问题,但我不想使用该Thread.Sleep(50000); …

testing selenium window webdriver

27
推荐指数
2
解决办法
9万
查看次数

如何使用Selenium Webdriver在浏览器中单击<input type = file>?

我正在使用Selenium 2 - WebDriver处理文件选择器对话框.信不信由你,我的问题不是处理操作系统原生的文件选择器.那部分我可以处理!

问题是让Selenium正确点击"选择文件"按钮.由于原始源html很简单<input type='file'>,浏览器确定如何将其呈现为字段和按钮.因此,按钮的放置和命名会根据浏览器而改变.我已经在Chrome中使用它,但仅仅是因为Chrome将按钮放在最左边的路线上,而Selenium恰好在默认情况下点击那里.

有任何想法吗?我不清楚这种类型的输入是否真的可以从DOM中导航......

selenium webdriver

27
推荐指数
2
解决办法
4万
查看次数

Selenium WebDriver:Fluent等待按预期工作,但隐式等待没有

我是Selenium WebDriver的新手,我正在努力理解"等待"元素出现的正确方法.

我正在测试一个包含一系列带有单选按钮答案的问题的页面.当您选择答案时,Javascript可能会启用/禁用页面上的一些问题.

问题似乎是Selenium"点击太快"而不是等待Javascript完成.我试过用两种方法解决这个问题 - 显式等待解决了这个问题.具体来说,这是有效的,并解决了我的问题:

private static WebElement findElement(final WebDriver driver, final By locator, final int timeoutSeconds) {
    FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(timeoutSeconds, TimeUnit.SECONDS)
            .pollingEvery(500, TimeUnit.MILLISECONDS)
            .ignoring(NoSuchElementException.class);

    return wait.until(new Function<WebDriver, WebElement>() {
        public WebElement apply(WebDriver webDriver) {
            return driver.findElement(locator);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

但是,我宁愿使用隐式等待而不是这样.我的网页驱动程序配置如下:

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Run Code Online (Sandbox Code Playgroud)

这没有解决问题,我得到一个NoSuchElementException.另外,我没有注意到10秒的暂停 - 它只是立即出错.我已经验证了代码中的这一行是用调试器命中的.我究竟做错了什么?为什么implicitlyWait不等待元素出现,但FluentWait呢?

注意:正如我所提到的,我已经有了解决方法,我真的只想知道为什么隐式等待不能解决我的问题.谢谢.

selenium webdriver

27
推荐指数
1
解决办法
5万
查看次数

Click()方法并不总是有效

我在Selenium WebDriver中的测试有问题.Click当程序试图单击按钮时,事件并不总是有效.在一次测试中,一切都很好,在其他测试中则不然.

每个测试都从一页开始.首先,用户必须从select组件中选择一个选项,然后用户单击一个按钮.

我想知道为什么有一次一切都好,当我第二次运行测试时它不是?

以下是查找和单击按钮的源代码:

public void clickContinueBtn() {    
    webElement = driver.findElement(By.xpath("//div[@class='btn magenta_s']/a/span"));
    webElement.click(); 
}
Run Code Online (Sandbox Code Playgroud)

java selenium webdriver

27
推荐指数
4
解决办法
7万
查看次数

STS IDE中的量角器 - >找不到update-config.json

目前我有Protractor v.5.1.1,Node.js v.6.10.0

所有量角器测试都在窗口控制台中工作,但是当我尝试从STS IDE运行它时,我得到以下错误.当然我做了'webdriver-manager update',但它根本没用.有谁知道如何解决这个问题?

当我使用或不使用'directConnect'时分别低于错误

[22:21:48] I/launcher - Running 1 instances of WebDriver
[22:21:48] I/direct - Using ChromeDriver directly...
[22:21:48] E/direct - Error code: 135
[22:21:48] E/direct - Error message: Could not find update-config.json. Run    'webdriver-manager update' to download binaries.
[22:21:48] E/direct - Error: Could not find update-config.json. Run 'webdriver-manager update' to download binaries.
at IError  (D:\STS_workspace\jgh\node_modules\protractor\built\exitCodes.js:5:1)
at ProtractorError (D:\STS_workspace\jgh\node_modules\protractor\built\exitCodes.js:10:9)
at BrowserError (D:\STS_workspace\jgh\node_modules\protractor\built\exitCodes.js:51:9)
at Direct.getNewDriver (D:\STS_workspace\jgh\node_modules\protractor\built\driverProviders\direct.js:62:31)
at Runner.createBrowser (D:\STS_workspace\jgh\node_modules\protractor\built\runner.js:194:43)
at q.then.then (D:\STS_workspace\jgh\node_modules\protractor\built\runner.js:338:29)
at _fulfilled (D:\STS_workspace\jgh\node_modules\q\q.js:834:54)
at self.promiseDispatch.done (D:\STS_workspace\jgh\node_modules\q\q.js:863:30) …
Run Code Online (Sandbox Code Playgroud)

javascript json webdriver protractor webdriver-manager

27
推荐指数
3
解决办法
3万
查看次数

如何捕获webdriver中页面发出的所有请求?Browsermob还有其他选择吗?

我正在使用Selenium2/WebDriver来测试我的Web应用程序.所有测试都是用Java编写的,并与Maven一起运行.

在使用webdriver打开页面时,我想捕获页面发出的所有请求(图像,js和css文件等).我使用这些数据主要有两个原因

  • 检查呼叫中的404(以及其他错误)
  • 检查分析代码是否正常工作(检查它是否正在发送正确的请求)

根据项目,我使用Firebug和Netexport或Browsermob代理.在这两种情况下,我都可以轻松获取HAR(Html ARchive)文件,解析它并提取我想要的数据.

问题在于:我对这些解决方案都不满意.当页面包含加载太长时间的视频时,我特别遇到获取HAR文件的问题.我正在寻找更稳定的东西.

所以,问题是:

Browsermob还有其他选择吗?我知道FiddlerCore,但它是一个.NET库,我的测试是用Java编写的.我也听说过Ajax DynaTrace,我知道有一些方法可以将它与Selenium集成,但我找到的文档是Selenium-RC而不是WebDriver.

有没有办法将DynaTrace与WebDriver集成或使用FiddlerCore与Java?

有没有其他方法可以实现我提到的目标?我正在寻找一个可以从我的代码中轻松控制的代理.将数据导出到HAR将是一个很好的选择.

java proxy selenium webdriver har

26
推荐指数
2
解决办法
5万
查看次数

如何处理Selenium中的打印对话框?

我必须处理打印对话框(在浏览器中单击ctrl-p时出现的对话框).我尝试过:

Alert printDialog = driver.switchTo().alert();
printDialog.dismiss();
Run Code Online (Sandbox Code Playgroud)

但它不起作用.另外,我无法抓住它的窗口把手,因为它不是一个窗口......

是否可以处理这些对象以及如何处理?

java selenium webdriver

26
推荐指数
3
解决办法
3万
查看次数

如何在python Webdriver中鼠标悬停

看来这是在webdriver中进行悬停/鼠标悬停的方法,至少在java api中是这样的:

Actions action = new Actions(driver);
action.moveToElement(element).build().perform();
action.moveByOffset(1, 1).build().perform();
Run Code Online (Sandbox Code Playgroud)

这可能在Python api中吗?python的webdriver api文档似乎没有提到类似的东西. http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html

如何在python webdriver中完成hover/mouseover?

python selenium webdriver selenium-webdriver

25
推荐指数
1
解决办法
3万
查看次数