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. I think this should at least work in theory, but I can't get access to any of the functions or elements on website 2. What am I doing wrong?