2017-05-17 22 views
0

我試圖運行簡單的Java Selenium代碼,但出現此錯誤 - 任何人都可以幫我弄清楚它嗎?Java.net中的java.net.MalformedURLException 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(); 
} 

}

+1

這意味着**鏈接失效**。什麼是URL? –

+0

我已通過鏈接** driver.get(「http://google.com」); ** –

+0

@PrashanthNagendra您能否考慮向我們展示您的作品? – DebanjanB

回答

0

看來您正在使用不正確的URL在get()方法。嘗試使用如下方法get()

driver.get("http://www.google.com"); 

URL must contains "http://" or "https://" to define its protocol.

修復代碼中,你可以嘗試一次低於內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-jmet‌​er- 
     3.1/bin/chromedri‌​ver.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){} 
} 

}

+0

是的,我通過了driver.get(「http://google.com」); –

+0

@PrashanthNagendra,請張貼WebDriver Sampler的截圖。 –

+0

先生我試了代碼,但又得到了這個錯誤 –