使用selenium啟動火狐瀏覽器,解決Unable to create new remote session問題


今天用火狐瀏覽器來做自動化,才啟動就報錯,提示不能創建新的session,不能啟動瀏覽器

問題原因:

火狐driver與火狐瀏覽器與selenium版本的不兼容

我使用的火狐driver是0.21.0 版本,下載地址:https://github.com/mozilla/geckodriver/releases

使用的火狐瀏覽器版本是60,下載地址:http://www.firefox.com.cn/download/

 

使用selenium-java的版本是3.12.0,因為是使用的maven,maven配置為

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.12.0</version>
</dependency>

  調試的代碼為

public class firefoxsrun {
	WebDriver driver;
	@BeforeClass
	public void beforeClass(){
		System.setProperty("webdriver.gecko.driver", "resources/geckodriver.exe");
		driver = new FirefoxDriver();
	    driver.get("http://www.baidu.com");
	
	}
	
	@Test
	public void test2(){
		System.out.println("成功啦");
		driver.findElement(By.id("kw")).sendKeys("testurl");
		driver.findElement(By.id("su")).click();
	}
	
}

  我的diver就放在我的項目目錄下的resource下

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM