首页 > 解决方案 > 获取 InvalidArgumentException

问题描述

package trails2110;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Demo01 {
    WebDriver driver;
    
    @Before
    public void setUp() throws Exception {
        System.setProperty("webdriver.chrome.driver", "D:\\Eclipse\\Drivers\\chromedriver.exe");
        System.out.println("1");
        driver= new ChromeDriver();
        System.out.println("2");
    }

    @After
    public void tearDown() throws Exception {
        driver.close();
    }

    @Test
    public void test() {
        String url= "www.hotstar.com";
        System.out.println("3");
        driver.get(url);
        System.out.println("4");
        String Title=driver.getTitle();
        System.out.println(Title);
    }
}

在控制台中直到 3 它被打印出来。我有最新版本的 chrome 和最新版本的 chrome 驱动程序。我尝试了多个驱动程序没有工作。我错过了什么吗?

我可以使用以下代码路由到 url

System.setProperty("webdriver.chrome.driver", "D:\\Eclipse\\Drivers\\chromedriver.exe");
        WebDriver driver= new ChromeDriver();
        String url = "https://www.google.com";
        String script = "window.location = \'"+url+"\'";        
        ((JavascriptExecutor) driver).executeScript(script);

它没有发生在 get() 方法和发生在 JavascriptExecutor 的任何原因?

标签: selenium

解决方案


您应该使用其协议声明 URL。所以

String url= "www.hotstar.com";
url = "https://" + url

推荐阅读