嘗試使用Selenium和SafariWebDriver。 使用的罐子 硒服務器獨立-2.33.0.jar - 運行Jetty服務器使用Java在使用Selenium WebDriver啓動Safari期間無法與SafariDriver建立連接
java -jar ./lib/selenium-server-standalone-2.33.0.jar
硒-java的2.33.0.jar (我沒有使用Maven安裝項目 - 剛剛下載的罐子,並用javac編譯)
javac -s ./src -cp ./classes:./lib/selenium-java-2.33.0.jar:./lib/selenium-server-standalone-2.33.0.jar ./src/jgf/Selenium2Example.java -d ./classes
寫一類是Selenium2Example或多或少複製/粘貼,但使用SafariWebDriver代替FirefoxWebDriver
但代碼執行時,我在Safari Web瀏覽器中使用Snow Leopard with Safari 5.1.9(6534.59.8)。
無法建立與SafariDriver
上的任何想法如何解決這個問題有關聯嗎?
順便說一句:我沒有使用通過註冊成爲Apple開發人員的證書源代碼編譯的Safari擴展 - 我認爲這適用於早期的jar版本。
下面是代碼
package jgf;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Selenium2Example {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
//WebDriver driver = new FirefoxDriver();
WebDriver driver = new SafariDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Alternatively the same thing can be done like this
// driver.navigate().to("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
// Should see: "cheese! - Google Search"
System.out.println("Page title is: " + driver.getTitle());
//Close the browser
driver.quit();
}
}
我想知道這是否是某種防火牆問題。所以嘗試禁用。然後我得到了一些奇怪的例外。首先在線程「Thread-3」中發生這種異常org.openqa.selenium.WebDriverException:無法卸載擴展 verExtension $ UninstallThread.run(SafariDriverExtension.java:293)然後在後續運行中線程「main」中的異常org.openqa.selenium .remote.UnreachableBrowserException:無法在45077後連接到SafariDriver ms – JGFMK
查看此相關評論 - 可以使用本地http://www.sqaforums進行確認。com/forums/selenium/149199-%5Bsafaridriver%5D-safari-can-not-find-element-webpage.html – JGFMK
您是否設法解決此問題? –