打开链接后填写表格的问题

时间:2018-09-18 18:55:32

标签: javascript

我正在学习JavaScript,因此决定创建一个脚本来

  1. 打开页面
  2. 填写页面上的表格
  3. 点击提交按钮
  4. 将打开一个新页面
  5. 从此页面获取数据并登录到控制台。

但是在页面从第1行打开之后,脚本的其余部分没有运行。

我如何完成此任务?

    loginPage=open("abc.com"); //Open this page to fill a form there
    var mainPage;
    loginPage.onload=function(){ //once the page gets loaded fire this function
            document.getElementById("username").value="123456789"; //fill username with this value
            document.getElementById("password").value="abcdefghijk"; //fill password with this value
            mainPage=document.getElementsByClassName("loginbutton")[0].click(); //press the login button
        }
    mainPage.onload=function(){
            x=document.getElementsByClassName("tabletext");  //grab the table
            target=x[22]; //since the content is in the 22nd index, assign it to target
            console.log(target.textContent); //log the value of text inside target to console.
    }

1 个答案:

答案 0 :(得分:0)

Is "abc.com" the same domain as the site that you're executing this script on? If it's not, it's simply not possible due to the fact that you're violating CORS / browser security measures. You cannot read the content from another domain using JS that doesn't explicitly allow all origins.

相关问题