小编Ada*_*unt的帖子

使用Java查找损坏的链接的Selenium WebDriver中的URL格式错误的异常

我在Selenium脚本中使用此代码来查找损坏的链接.所以这是我编写的代码,但在运行时我遇到了格式错误的异常.

public void countNoOfLinksInHomePage(WebDriver fd) throws IOException{
        List<WebElement> listOfElements=fd.findElements(By.tagName("a"));
        //System.out.println(listOfElements.get(0));
        //log.info("name of links is " +listOfElements);
        int countOfElements=listOfElements.size();
        log.info("Total no of links in Homepage is:: " +countOfElements);

        //for(int i=0;i<countOfElements;i++){

            int responseCode=getResponseCode(listOfElements.get(1).getAttribute("href"));
            log.info("Response code of element at index 1 is:: " + responseCode);

            //break;
        //}
    }

    public static int getResponseCode(String url) throws MalformedURLException, IOException{

        URL u=new URL(url);
        HttpURLConnection huc=(HttpURLConnection)u.openConnection();
        huc.setRequestMethod("GET");
        huc.connect();
        return huc.getResponseCode();
    }
Run Code Online (Sandbox Code Playgroud)

testng跟踪是:

java.net.MalformedURLException:未知协议:javascript

java selenium broken-links selenium-webdriver

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

TestNG:@BeforeClass和@BeforeTest的优先级

我一直在用TestNG和有问题有两个注解,@BeforeTest@BeforeClass。我想知道两者是否都适用?

testng selenium

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