2017-05-17 15 views
0

シンプルなJava Seleniumコードを実行しようとしましたが、このエラーが発生しました。Java Seleniumコードのjava.net.MalformedURLException

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が無効であることを意味し**。 URLは何ですか? –

+0

私は** driver.get( "http://google.com"); ** –

+0

@PrashanthNagendraとしてリンクを渡しました。 – DebanjanB

答えて

0

あなたがget()方法に誤ったURLを使用しているようです。以下のような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

私はコードを試しましたが、このエラーが再び発生しました –

関連する問題