【问题标题】:Unable to establish a connection with the SafariDriver during launching Safari with Selenium WebDriver using Java在使用 Java 使用 Selenium WebDriver 启动 Safari 期间无法与 SafariDriver 建立连接
【发布时间】:2013-07-07 21:49:21
【问题描述】:

尝试使用 Selenium 和 SafariWebDriver。 使用罐子 selenium-server-standalone-2.33.0.jar - 运行 Jetty 服务器

java -jar ./lib/selenium-server-standalone-2.33.0.jar 

selenium-java-2.33.0.jar (我没有使用 Maven 来设置项目 - 只是下载了 jars,并使用 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 建立连接

关于如何解决这个问题的任何想法?

顺便说一句:我没有使用通过注册为 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
  • 看到了这个相关评论-可以在本地使用sqaforums.com/forums/selenium/…确认
  • 你解决了这个问题吗?

标签: java macos selenium-webdriver safari safaridriver


【解决方案1】:

我在 2.34 中遇到了同样的问题,所以我回到 2.31 并且一切似乎都很好,没有遇到 safari 的“无法建立连接”错误。

【讨论】:

    【解决方案2】:

    考虑操作系统 Windows。
    先决条件:在 Windows 上安装 Safari

    1. 转到http://docs.seleniumhq.org/download/
    2. 向下滚动 -> 转到“SafariDriver”部分并下载“SafariDriver.safariextz”
    3. 双击“SafariDriver.safariextz”(之前下载的)
    4. Safari 将打开一个包含“安装”按钮的弹出窗口 -> 单击安装按钮
    5. 现在转到 Safari 的首选项,您会看到已安装 WebDriver(在我的情况下为 WebDriver 2.48.0)(选中启用 WebDriver 复选框)
    6. 现在是时候实例化 SafariDriver 并获取所需的 URL,如下所示:

      WebDriver 驱动程序 = 新的 SafariDriver();
      driver.get("https://www.packtpub.com/web-development/mastering-selenium-testing-tools-video");

    【讨论】:

    • 我使用的是 Windows 7
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多