2017-05-17 21 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

先生我试了代码,但又得到了这个错误 –