尝试使用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
您是否设法解决此问题? –