java Selenium代码中的java.net.MalformedURLException
我试图运行简单的Java Selenium代码,但遇到了这个错误-有人能帮我解决吗java Selenium代码中的java.net.MalformedURLException,java,selenium,automation,jmeter,jmeter-plugins,Java,Selenium,Automation,Jmeter,Jmeter Plugins,我试图运行简单的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.ch
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){}
}
}您似乎在
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");
如系统类的javadoc中所述:
设置由指定键指示的系统属性
首先,如果存在安全管理器,则其
调用SecurityManager.checkPermission方法时使用
PropertyPermission(键,“写入”)权限。这可能会导致
正在引发SecurityException。如果没有引发异常,则
指定的属性设置为给定值
参数:
键-系统属性的名称。值-所选对象的值
系统属性
返回:
系统属性的上一个值,如果没有,则为null
一个。抛出:SecurityException-如果存在安全管理器并且
其checkPermission方法不允许设置指定的
财产。NullPointerException-如果键或值为null。
IllegalArgumentException-如果键为空
使用以下命令:
System.setProperty("webdriver.chrome.driver","D://apache-jmeter-3.1//bin//chromedriver.exe");
如系统类的javadoc中所述:
设置由指定键指示的系统属性
首先,如果存在安全管理器,则其
调用SecurityManager.checkPermission方法时使用
PropertyPermission(键,“写入”)权限。这可能会导致
正在引发SecurityException。如果没有引发异常,则
指定的属性设置为给定值
参数:
键-系统属性的名称。值-所选对象的值
系统属性
返回:
系统属性的上一个值,如果没有,则为null
一个。抛出:SecurityException-如果存在安全管理器并且
其checkPermission方法不允许设置指定的
财产。NullPointerException-如果键或值为null。
IllegalArgumentException-如果键为空
这意味着Url无效。URL是什么?我以驱动程序的身份传递了链接。get(“);看起来你写的是'stem'而不是'System',这意味着URL无效。URL是什么?我以驱动程序的身份传递了链接。get(”);似乎你写的是“stem”而不是“System”@PrashanthNagendra,请发布WebDriver Sampler.javax.script.ScriptException的屏幕截图:源文件:内联评估:``import org.openqa.selenium.WebDriver;导入org.openqa.selenium.chrome.ChromeDr…“”令牌解析错误:先生,我尝试了异常处理代码,但没有worked@PrashanthNagendra请使用此代码。请注意setProperty中的双斜杠。谢谢<代码>系统.setProperty(“webdriver.chrome.driver”,“C:\\pathto\\my\\chromedriver.exe”);WebDriver驱动程序=新的ChromeDriver();驱动程序。获取(“http://www.google.com");@PrashanthNagendra,请发布WebDriver Sampler.javax.script.ScriptException的屏幕截图:源文件:内联评估:``import org.openqa.selenium.WebDriver;导入org.openqa.selenium.chrome.ChromeDr…“”令牌解析错误:先生,我尝试了异常处理代码,但没有worked@PrashanthNagendra请使用此代码。请注意setProperty中的双斜杠。谢谢<代码>系统.setProperty(“webdriver.chrome.driver”,“C:\\pathto\\my\\chromedriver.exe”);WebDriver驱动程序=新的ChromeDriver();驱动程序。获取(“http://www.google.com");代码>请解释我不明白的原因,因为答案没有解释的内容。我可能会标记这个答案。请解释为什么我不理解这个答案,而这个答案没有要解释的内容。我可能会标记这个答案。