войти через фантом js - как вводить значения? - PullRequest
0 голосов
/ 14 апреля 2020

Я хочу войти на этот сайт https://www.wm.com/us/ (вы можете видеть этот сайт, только если вы из США или имеете прокси-сервер США) Это страница входа

https://www.wm.com/us/en/mywm/locate?redirect=/us/en/mywm

Я написал скрипт в фантоме js, чтобы получить исходный код страницы с этой страницы, и он работает хорошо. Вот код:

var page = require('webpage').create();
page.onError = function(msg, trace) {
  //prevent js errors from showing in page.content
  return;
};
page.open("https://www.wm.com/us/en/mywm/locate?redirect=/us/en/mywm", function(status) {
    setTimeout(function(){
       console.log(page.content);

    }, 10000);
});

Это важная часть из исходного кода:

<form class="TextInputForm">
   <div class="TextInput widget-card-input">
      <input class="inputMaterial  " type="email" maxlength="" placeholder="" id="loginEmail">
      <label class="" for="loginEmail">
         Email
      </label>
      <div class="TextInput__error-message pt-2" style="min-height: 2.5rem;">
         <div class="validation-error">
         </div>
      </div>
   </div>
   <div class="TextInput widget-card-input" style="margin-top: 1rem; margin-bottom: 0px;">
      <input class="inputMaterial  password" type="password" maxlength="" placeholder="" id="loginPassword">
      <label class="" for="loginPassword">
         Password
      </label>
      <button class="btn-right btn-right-ie" type="button" style="font-size: 14px; color: rgb(103, 105, 109); outline: none; cursor: pointer; position: relative; left: 0px; top: -0.4rem; transition: left 0.3s; -webkit-transition: left 0.3s;">
         SHOW
      </button>
      <div class="TextInput__error-message pt-2" style="min-height: 2.5rem;">
         <div class="validation-error">
         </div>
      </div>
   </div>
   <div class="mt-3">
      <div class="login-options-wrapper">
         <span class="forgot-link">
            <button class="link" type="button">
               Forgot password?
            </button>
         </span>
      </div>
      <div>
         <button class="Button a-taggable btn inter-font-weight-bold rounded-0 d-flex flex-column align-items-center justify-content-center ButtonPrimary text-uppercase px-5 my-3 ml-3" name="" type="submit" analytics="LOG IN" aria-label="" style="height: 3.125rem; font-size: 1rem;">
            LOG IN
         </button>
      </div>
      <div class="login-footer">
         <div class="login-copy">
            Already have an account or need to register?
         </div>
         <button class="link register" type="button">
            Sign Up
         </button>
      </div>
   </div>
</form>

Теперь я хочу ввести пользователя, передать форму и отправить ее, чтобы я мог войти на веб-сайт, а затем на go на домашней странице и проверить, вошел ли я. Что касается формы, я добавил этот код:

page.evaluate(function(){
            document.querySelector('input[type="email"]').value="ccc@ccc.com"; 
            document.querySelector('input[type="password"]').value="ccc"; 
            document.forms[1].submit();  
        });

Но когда я запускаю скрипт, ничего не происходит, что я сделал не так, какая-нибудь помощь?

...