selenium - 获取 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 的任何原因?
解决方案
您应该使用其协议声明 URL。所以
String url= "www.hotstar.com";
url = "https://" + url
推荐阅读
- php - 使用 word press 和 ACF 删除循环中的重复代码
- laravel - 如何在 laravel-6.20 中安装“Laravelium Sitemap 包”
- .net - 如何在 NSubstitute 中模拟属性设置器
- r - Geom_segment 没有读取缺失的美学:x、y、xend 和yend Piper Plot
- javascript - 从 CommonJS 应用程序导出 const 并要求它们在另一个文件中
- asp.net-core-mvc - 不要在 ASP.NET Core 中显示 TempData 的消息
- unit-testing - 如何通过 Apex 代码为 Apex 测试类创建重复/匹配规则?
- amazon-web-services - 使用 AWS Golang SecretsManager 缓存客户端的 AWS Lambda 函数的正确资源权限是什么?
- angular - 在 AWS CodeBuild 上为 Angular 项目使用本地依赖
- python - 遇到空页面时如何告诉scrapy停止抓取下一页?