小编aim*_*ire的帖子

Selenium WebDriver可以工作但是SLOW(Java)

我正在使用Selenium WebDriver截取网页截图.它运行得很好.但是,从我在eclipse中运行的时间到我本地驱动器中显示的屏幕截图是7-10秒.大多数延迟似乎都在推出Firefox.

码:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.cnn.com");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\test\\screenshot.png"));
Run Code Online (Sandbox Code Playgroud)

我怎样才能加快这个过程?有没有办法可以使用已经打开的Firefox浏览器来保存开新的浏览器?这段代码有点沉重吗?

详细信息:使用eclipse在CentOS盒和Win7盒上尝试.myspeedtest.net显示22Mbps下行和1 Mbps上行.

selenium screenshot webdriver selenium-webdriver

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

Selenium WebDriver可靠的测试

我知道这个问题以前被问过很多次,但是我仍然找不到适合我的解决方案。在大多数情况下,我使用Selenium WebDriver运行测试时,它们会因“ NoSuchElementException”而失败。我尝试使用显式和隐式等待,但似乎没有任何效果。因此,除了使用Waits之外,还有其他方法可以使测试更可靠吗?

我在FirefoxDriver中使用selenium-java-2.31.0。以下是一些我试图使测试更可靠的代码示例:

public void waitAndClickElement(WebDriver driver, final By selector) {
        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(50, TimeUnit.SECONDS)
                .pollingEvery(5, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);
        WebElement elementToClick = wait
                .until(new Function<WebDriver, WebElement>() {
                    public WebElement apply(WebDriver driver) {
                        return driver.findElement(selector);
                    }

                });
        waitForElementVisible(driver, selector);
        elementToClick.click();
         }
Run Code Online (Sandbox Code Playgroud)

..和这个:

public WebElement waitForElementPresent(WebDriver driver, final By selector){
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(70, TimeUnit.SECONDS)
            .pollingEvery(5, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);
    WebElement elementToClick = wait
            .until(new Function<WebDriver, WebElement>() {
                public WebElement apply(WebDriver driver) {
                    return driver.findElement(selector);
                }
            });
    return elementToClick; …
Run Code Online (Sandbox Code Playgroud)

selenium selenium-rc selenium-webdriver

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

如何将数组中的所有项目分成两倍?

我是一个完全的初学者,我对数组有一点问题.该程序的要点是计算向量的归一化.第一部分只是将数组的长度计算为int,称为sum,然后我想用这个总和来划分数组v中的所有项.normal [] = v [a]/sum; 这条线显然是个问题,但我该怎么办?

public static double[] normalized(double[] v){

    double sum = 0;

    for(int counter = 0; counter < v.length; counter++){
        sum += Math.pow(v[counter], 2);
    }
        sum = Math.sqrt(sum);
        double[] normal;
    for(int a = 0; a < v.length; a++){      
        normal[] = v[a]/sum;
    }
return normal;
}
Run Code Online (Sandbox Code Playgroud)

java

4
推荐指数
1
解决办法
8863
查看次数

从Angular 4升级到5:"NodeInvocationException:没有PlatformRef的提供者!"

我已经将应用程序从Angular 4.2升级到5,但是出现了这个错误: unhandled exception occurred while processing the request更具体地说:

NodeInvocationException:没有PlatformRef的提供者!错误:没有PlatformRef的提供程序!at injectionError(e:\ myapp\ClientApp\dist\vendor.js:12066:90)

该应用程序还使用webpackASP.NET Core.

我安装了node v9.1,和typescript 2.6.1.

我也package.json用命令更新了:

npm install @angular/common@latest @angular/compiler@latest @angular/compiler-cli@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest @angular/animations@latest typescript@latest 
Run Code Online (Sandbox Code Playgroud)

然后,运行以下内容:

 npm install --save-dev @ngtools/webpack@latest
Run Code Online (Sandbox Code Playgroud)

我也用过HttpClient而不是Http:

import { HttpClient } from '@angular/common/http'; 
.....
 getThings() {
        return this.http.get('/api/things');

  }
Run Code Online (Sandbox Code Playgroud)

如果我降级回Angular 4,该应用程序工作正常,我的思路中是否有任何错误的做法?

node.js npm asp.net-core angular angular5

4
推荐指数
1
解决办法
6735
查看次数

Python:String不会转换为float

几个小时前我写了这个程序:

while True:
    print 'What would you like me to double?'
    line = raw_input('> ')
    if line == 'done':
        break
    else:
        float(line)              #doesn't seem to work. Why?
        result = line*2
        print type(line)         #prints as string?
        print type(result)       #prints as string?
        print " Entered value times two is ", result

print 'Done! Enter to close'
Run Code Online (Sandbox Code Playgroud)

据我所知,它应该工作正常.问题是,当我输入一个值,例如6,我收到66而不是12.看起来这部分代码:

float(line)
Run Code Online (Sandbox Code Playgroud)

不起作用,并将行视为字符串而不是浮点数.我只做了一天python,所以它可能是一个新手的错误.谢谢你的帮助!

python string

2
推荐指数
2
解决办法
2324
查看次数

使用selenium Firefox webdriver将<HTML> <head> <title>文本清空

我在Windows 7上使用Firefox 21和C#WebDriver 2.33.我很困惑为什么以下测试失败(我只是检查我的配置设置是否正确).这在其他浏览器中传递.

[Test]
public void FirefoxDriverWorks()
{
    var firefoxDriver = new FirefoxDriver();
    TestGoogleStillExists(firefoxDriver);
    firefoxDriver.Quit();
}

public void TestGoogleStillExists(IWebDriver webDriver)
{
    webDriver.Navigate().GoToUrl("http://www.google.com");
    var title = webDriver.FindElement(By.CssSelector("head title"));
    Assert.That(title.Text, Is.EqualTo("Google"));
}
Run Code Online (Sandbox Code Playgroud)

c# firefox selenium webdriver selenium-webdriver

1
推荐指数
1
解决办法
2596
查看次数

javascript onclick功能放大文字

我不知道为什么,但我似乎无法让这个工作.

这是我放大字体的功能.

<script type="text/javascript">
    function growText() {
        var text = document.getElementById("t_left_text");
        text.font-size=22px;        
</script>
Run Code Online (Sandbox Code Playgroud)

这就是我所说的

<div id="t_left" onclick="growText()">
    <br />
    <p id="t_left_text">Mountains are beautiful land structures <br /> that are a result of plate tectonics.</p>
    <br />
</div>
Run Code Online (Sandbox Code Playgroud)

html javascript onclick

0
推荐指数
1
解决办法
1561
查看次数

如何在WebDriver中获取元素的父级

<div class="field select-container invalid" data-tooltip="Error message." "name="birthDate">
<div class="stack-wrap gutter-col-wrap-1">
<div class="stack size1of3">
<div class="gutter-col-1">
    <div class="form-selectbox full-width">
    <select name="day">
        <option value="">Giorno</option>
        <option value="01">1</option>
Run Code Online (Sandbox Code Playgroud)

使用WebElement el = browser.switchTo()。activeElement()时,焦点位于“名称”属性上。需要找到“ data-tooltip”的父项才能在屏幕上获取错误消息。请帮忙。

selenium-webdriver

0
推荐指数
1
解决办法
3391
查看次数