dimanche 31 juillet 2016

HTML/Javascript: Pressing a button on a website with javascript

I'm trying to simply (in a javascript environment managed in HTML script tags) load a webpage and press a button on that page. I also want to be able to read data off of the webpage, but that should be self-explanatory once I get button pressing working. I've looked around for solutions but none seem to work.

For sake of a controlled environment, I have 2 simple websites. On the first there is a button which calls a javascript function, in which I attempt to load website 2 and press another button. On website 2, there is a single button that, when pressed, calls a javascript function and generates a dialogue box.

I can load page 2 using window.open(), and I believe that has a return type which is a handle to the website, which I save. I've tried using that handle to call the javascript function in webpage 2. I've tried getting the element by ID and using click()/submit(). And here's the code to the current attempt:

Website 1:

<html>
    <body>
        <script  language = "javaScript">
            function print() {
                //alert('Hello World');

                var win = window.open("file:///Users/Jacob/Documents/2ndWebTest.html");

                win.document.form[0].submit();
            }
        </script>
        <p><button onclick = "print()">test</button></p>
    </body>
</html>

Website 2:

<html>
    <body>
        <script  language = "javaScript">
            function testFunc() {
                alert('Hello World');
            }
        </script>
        <p><button onclick = "testFunc() id = "buttonTest"">test</button></p>
    </body>
</html>

I'm trying to navigate through a website hierarchy and pull data from it. Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire