【问题标题】:Problems with opening local html with watir用 watir 打开本地 html 的问题
【发布时间】:2016-04-12 14:46:22
【问题描述】:

我的 C 盘上有一个本地 html 文件 我正在尝试打开它并单击一个按钮。 Html 文件如下所示:

<html>
<body>
    <div id="first">
        <div id="second">
            <div id="third">
                <button id="button">Text</button>
            </div>
        </div>
    </div>
    <p id="txt">Not clicked yet</p>
    <script type="javascript">
        var par = document.getElementById('txt');
        function clicked() {
            if (par.innerText == 'Clicked') {
                par.innerHTML = 'Clicked Again';
            } else {
                par.innerHTML = 'Clicked';
            }
        }
    </script>
</body>

我正在尝试使用以下代码打开文件并单击按钮:

require 'watir-webdriver'
browser = Watir::Browser.new :ie
browser.goto "file://C:\\test.html"
browser.button(id: 'button').click

但我收到以下异常:

Watir::Exception::NoMatchingWindowFoundException: browser window was closed

如果我转到任何其他非本地 URL,一切正常。 有谁知道如何解决这个问题?

我的系统参数:

Windows 7 64 bit, IEDrvierServer 2.49, IE11

【问题讨论】:

  • 您必须在 URL 前添加 file:// 吗?我隐约记得watir-classic(或使用 IE 时的watir)需要它,而您正在使用watir-webdriver
  • 是的,否则在url前面附加http:\\www

标签: html internet-explorer watir watir-webdriver


【解决方案1】:

对于 Windows,您应该使用正斜杠,并注意开头的 3 个正斜杠:file:///C:/Documents/Foo

另外,您应该更新到最新的 IEDriverServer 2.53.1(使用 32 位版本)。

如果这不能解决问题,请编辑问题以包含完整的回溯。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2013-05-03
    • 1970-01-01
    相关资源
    最近更新 更多