2016-08-05 55 views
1

我已經將selenium webdriver版本更新爲3.0 beta,之後我在eclipse ide中生成了一個腳本。在我運行該腳本後,Firefox已打開,但未重定向到該URL。使用selenium web驅動3.0後Firefox 48並沒有打開腳本中的任何URL

這是硒IDE生成的簡單代碼

import java.util.regex.Pattern; 
import java.util.concurrent.TimeUnit; 
import org.testng.annotations.*; 
import static org.testng.Assert.*; 
import org.openqa.selenium.*; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.support.ui.Select; 

public class Selenium { 
    private WebDriver driver; 
    private String baseUrl; 
    private boolean acceptNextAlert = true; 
    private StringBuffer verificationErrors = new StringBuffer(); 

    @BeforeClass(alwaysRun = true) 
    public void setUp() throws Exception { 
    driver = new FirefoxDriver(); 
    baseUrl = "https://www.google.co.in/"; 
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
    } 

    @Test 
    public void testF() throws Exception { 
    driver.get(baseUrl + "/?gws_rd=ssl"); 
    driver.findElement(By.id("lst-ib")).clear(); 
    driver.findElement(By.id("lst-ib")).sendKeys("hi"); 
    driver.findElement(By.id("lst-ib")).clear(); 
    driver.findElement(By.id("lst-ib")).sendKeys("hifi"); 
    } 

    @AfterClass(alwaysRun = true) 
    public void tearDown() throws Exception { 
    driver.quit(); 
    String verificationErrorString = verificationErrors.toString(); 
    if (!"".equals(verificationErrorString)) { 
     fail(verificationErrorString); 
    } 
    } 

    private boolean isElementPresent(By by) { 
    try { 
     driver.findElement(by); 
     return true; 
    } catch (NoSuchElementException e) { 
     return false; 
    } 
    } 

    private boolean isAlertPresent() { 
    try { 
     driver.switchTo().alert(); 
     return true; 
    } catch (NoAlertPresentException e) { 
     return false; 
    } 
    } 

    private String closeAlertAndGetItsText() { 
    try { 
     Alert alert = driver.switchTo().alert(); 
     String alertText = alert.getText(); 
     if (acceptNextAlert) { 
     alert.accept(); 
     } else { 
     alert.dismiss(); 
     } 
     return alertText; 
    } finally { 
     acceptNextAlert = true; 
    } 
    } 
} 
+0

您能否添加更多關於您錯誤的信息?你配置了gecko驅動程序(請參閱https://stackoverflow.com/questions/37785686/how-to-use-the-gecko-executable-with-selenium)? –

回答

0

這是因爲能力問題,就像提供給硒從其他瀏覽器廠商的其他司機,Mozilla發佈了一個可執行的呼叫geckodriver將運行與瀏覽器一起。

您需要下載最新的可執行geckodriver和設置從您的計算機下載的這張路徑系統屬性以你的測試用例與Firefox的驅動程序如下運行:

System.setProperty("webdriver.gecko.driver","path/to downloaded/geckodriver.exe"); 
DesiredCapabilities capabilities = DesiredCapabilities.firefox(); 
capabilities.setCapability("marionette", true); 
WebDriver driver = new FirefoxDriver(capabilities); 

//Now do your further stuff with Firefox driver 
0

要運行出口IDE測試,確保leg-rc軟件包位於 類路徑中。

在Selenium 3中提到了哪些更改日誌。請參閱change log

相關問題