使用Selenium和SafariWebDriver一起尝试。 使用罐子 selenium-server-standalone-2.33.0.jar - 运行Jetty服务器
java -jar ./lib/selenium-server-standalone-2.33.0.jar
硒 - java的2.33.0.jar (我没有使用Maven来设置项目 - 只是下载了jar,并使用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和Safari 5.1.9(6534.59.8))。
无法与SafariDriver建立连接
关于如何解决这个问题的任何想法?
BTW:我没有使用通过注册为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();
}
}
答案 0 :(得分:0)
我在2.34遇到了同样的问题,所以我回到了2.31,一切看起来都很好,没有得到'无法与safari建立连接'错误。
答案 1 :(得分:0)
考虑操作系统Windows 先决条件:在Windows上安装Safari
现在是时候实例化SafariDriver并获得所需的URL,如下所示:
WebDriver driver = new SafariDriver();
driver.get(&#34; https://www.packtpub.com/web-development/mastering-selenium-testing-tools-video&#34);