尝试使用Selenium将存储在html读取方法中的字符串值传递到文本字段

时间:2014-05-10 19:35:31

标签: java testing selenium junit

以下是方法:

package com.abstractions.authentication;

import java.net.*;
import java.util.Scanner;

public class ReadHtml {

private static URL u;
private static Scanner s;
public static String html;

public static String getUrl(String newUrl) throws Exception
{
    u = new URL(newUrl);
    s = new Scanner(u.openStream());

    while (s.hasNext())
    {
        String line = s.nextLine();

        try
        {
            StringBuilder sb = new StringBuilder();

            while (s.hasNext())
            {
                sb.append(line);
                sb.append("\n");
                line = s.nextLine();
            }
            sb.toString();
            html = sb.toString();
        }
        finally
        {

        }
    }

    return html;
 }
}

以下是测试:

@Test
public void getHtmlOfUrl() throws Exception
{
    WebDriver browser = new FirefoxDriver();

    browser.navigate().to("https://crimestoppers-uk.org/give-information/give-information-online/");
    Thread.sleep(3000);
    String inputHtml = ReadHtml.getUrl("http://www.testforce.co.uk");
    browser.findElement(By.id("tx_desc")).sendKeys(inputHtml);
}

问题:字符串值似乎保持为null,因此不会在文本字段中输入任何内容。

0 个答案:

没有答案