Java 无法使用selenium脚本在mozilla firefox中写入URL。即使是月食也不会';没有显示任何错误
尝试使用selenium脚本测试宜家主页。Mozilla fire fox已打开,但url已在地址栏中输入Java 无法使用selenium脚本在mozilla firefox中写入URL。即使是月食也不会';没有显示任何错误,java,selenium,testing,mozilla,Java,Selenium,Testing,Mozilla,尝试使用selenium脚本测试宜家主页。Mozilla fire fox已打开,但url已在地址栏中输入 package ikea; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class ikeaautomation { public static void main(String[] args) { // TODO A
package ikea;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ikeaautomation {
public static void main(String[] args) {
// TODO Auto-generated method stub
// declaration and instantiation of objects/variables
WebDriver driver ;
System.setProperty("webdriver.firefox.marionette","C:\\Users\\orange\\Downloads\\geckodriver.exe");
driver = new FirefoxDriver();
String baseUrl = "http://ikea.in";
String expectedTitle = "IKEA";
String actualTitle = "";
// launch Fire fox and direct it to the Base URL
driver.get(baseUrl);
// get the actual value of the title
actualTitle = driver.getTitle();
/*
* compare the actual title of the page with the expected one and print
* the result as "Passed" or "Failed"
*/
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
//close Fire fox
driver.close();
// exit the program explicitly
System.exit(0);
}
}
以下是您问题的答案: 当您通过Selenium Java绑定使用Selenium 3.4.0、geckodriver v0.17.0、Mozilla 53.0而不是
webdriver.firefox.marionette
时,您必须通过System.setProperty
提及
如下:
System.setProperty("webdriver.gecko.driver","C:\\Users\\orange\\Downloads\\geckodriver.exe");
Rest您的代码工作正常:
修改代码:
// launch Fire fox and direct it to the Base URL
driver.get(baseUrl);
// get the actual value of the title
actualTitle = driver.getTitle();
System.out.println("Actual : "+actualTitle);
System.out.println("Expect : "+expectedTitle);
/*
* compare the actual title of the page with the expected one and print
* the result as "Passed" or "Failed"
*/
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
控制台输出:
Actual : IKEA
Expect : IKEA
Test Passed!
如果这能回答您的问题,请告诉我。谢谢!!但在进行相同的修改后,控制台中出现错误:用法:C:\Users\orange\Downloads\geckodriver.exe[OPTIONS]C:\Users\orange\Downloads\geckodriver.exe:Unknown option--port=44135能否更新更新的代码块和问题区域中更新的完整错误堆栈跟踪?似乎
geckodriver
正在随机尝试打开不可用的端口44135
。尝试重新启动系统一次。谢谢谢谢!!更新geckodriver并重新启动系统后,它可以工作