[英]java.net.MalformedURLException in Java Selenium code
我試圖運行簡單的Java Selenium代碼,但是我遇到了這個錯誤 - 任何人都可以幫我解決這個問題嗎?
import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class test
{
public static void main(String[] args)
{
stem.setProperty("webdriver.chrome.driver","D:/apache-jmeter-3.1/bin/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
String Title = driver.getTitle();
//compare the actual title of the page with the expected one
if (Title.contentEquals("Google"))
{
System.out.println("Test Passed!");
}
else
{
System.out.println("Test Failed");
}
driver.close();
}
}
看來你在get()
方法中使用了不正確的url。 嘗試使用如下的get()
方法:
driver.get("http://www.google.com");
URL必須包含“http://”或“https://”才能定義其協議。
修復你的代碼,你可以在WebDriver Sampler
嘗試下面一次:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class test {
public static void main(String[] args) {
try{
System.setProperty("webdriver.chrome.driver","D:/apache-jmeter-
3.1/bin/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
String Title = driver.getTitle();
if (Title.contentEquals("Google")){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
driver.close();
} catch (Exception e){}
}
}
用這個:
System.setProperty("webdriver.chrome.driver","D://apache-jmeter-3.1//bin//chromedriver.exe");
如System類的javadoc中所述:
設置指定鍵指示的系統屬性。
首先,如果存在安全管理器,則使用PropertyPermission(key,“write”)權限調用其SecurityManager.checkPermission方法。 這可能會導致拋出SecurityException。 如果未引發任何異常,則將指定的屬性設置為給定值。
參數:
key - 系統屬性的名稱。 value - 系統屬性的值。
返回:
系統屬性的先前值,如果沒有,則返回null。 拋出:SecurityException - 如果存在安全管理器且其checkPermission方法不允許設置指定的屬性。 NullPointerException - 如果key或value為null。 IllegalArgumentException - 如果key為空。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.