3

I have a local html file on my C drive and I am trying to open it and click on a button. Html file looks like this:

<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>

I am trying to use following code to open the file and click on a button:

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

but I am getting following exception:

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

if I go to to any other non local URLs everything works fine. Does anyone knows how to resolve this issue?

My system params:

Windows 7 64 bit, IEDrvierServer 2.49, IE11
2
  • Do you have to prepend file:// to the URL? I vaguely recall that was needed for watir-classic (or watir when using IE), and you are using watir-webdriver.
    – orde
    Apr 12, 2016 at 18:10
  • Yes, otherwise it appends http:\\www in front of url Apr 12, 2016 at 18:21

1 Answer 1

2

For Windows you should use forward slashes, and note the 3 forward slashes at the beginning: file:///C:/Documents/Foo

Also, you should update to the latest IEDriverServer 2.53.1 (use the 32 bit version).

If this doesn't fix it, please edit the question to include a full backtrace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.