0

Problem: Can't get code to 'click' button to execute action

Context: I'm able to get the element and change it from disabled to visible so I know I have the button class name correct in the command prior to this one but for whatever reason when the code gets to this switch case nothing happens; and no error is provided in the xcode console. There is no button input id and no form name associated either.

Question: Since I'm certain I have the getElementsByClassName....click() part correct, and I know this is the only element on the page with this name is there another way to execute the 'click'

Website HTML code:. [Last few lines of code]

<div class="mr-0 mr-md-5 pr-md-4 mb-4">
   <p class="mb-1 body-s" role="" aria-live="">Password</p>
   <span class="aria-hidden-logic d-none" aria-hidden="false">
      <label class="body-xs font-weight-bold mt-lg-2 mt-xl-2" for="oldPassword"></label>. 
   </span>
   <div class="input-controller aria-hidden-logic mb-2" aria-hidden="false">
      <input class="form-control is-invalid" type="password" id="oldPassword" placeholder="Old password" maxlength="40" aria-describedby="error-oldPassword" aria-label="oldPassword" value="">
      <button class="body-xs show-hide-btn" aria-label="Show Current Password">Show</button>
   <div aria-live="polite">
      <div class="error-class" id="error-oldPassword">Please enter your password</div>. 
      </div>
   </div>
   <span class="aria-hidden-logic d-none" aria-hidden="false">
      <label class="body-xs font-weight-bold mt-lg-2 mt-xl-2" for="newPassword"></label>. 
   </span>
   <div class="input-controller aria-hidden-logic mb-2" aria-hidden="false">
      <input class="form-control " type="password" id="newPassword" placeholder="New password" maxlength="40" aria-describedby="error-newPassword" aria-label="newPassword" value="">
      <button class="body-xs show-hide-btn" aria-label="Show New Password">Show</button>. 
      <div aria-live="polite"></div>
   <span>
   <ul class="ul-list-helpText">
      <li class="">Password must be 8-40 characters long.</li>
      <li class="">Your new password cannot be the same as your old password.</li>
      </ul>
   </span>
   </div>
   <div class="d-flex justify-content-end">
       <button type="button" class="btn btn-link body-s h-auto my-2 mr-3">Cancel</button>.   
       <button type="button" class="btn btn-secondary core-btn uca-button btn btn-sm btn-primary">Save</button>
   </div>
</div>

Swift Code [Doesn't work to click Save button]

 webView.evaluateJavaScript("document.getElementsByClassName('btn btn-secondary core-btn uca-button btn btn-sm btn-primary')[0].click();"){
                (result, error) -> Void in
       
                print(error)
           
            }

Swift Code [Works to enable Save button - when it's originally disabled]

            webView.evaluateJavaScript("document.getElementsByClassName('btn btn-secondary core-btn uca-button btn btn-sm btn-primary')[0].disabled = false;"){
            (result, error) -> Void in
            print(result)
            print(error)
        }
5
  • What does the button do? Commented Aug 31, 2022 at 20:46
  • @Asteroid its "save" button to save a password change Commented Aug 31, 2022 at 21:08
  • Any ideas for a long press/click or any method to create an error for this command would be super helpful also. It's bizarre to me that the code thinks both the result and errors are nil for the click Commented Aug 31, 2022 at 21:44
  • Please share enough code so I can easily run and reproduce the problem. PS, in my answer to a different question, there might be something that you find helpful: stackoverflow.com/a/72503950/4490923 Commented Aug 31, 2022 at 23:30
  • @Asteroid The place in the sequence of steps isn't easily shareable in its current form and without some extra external account setup with a third party so its probably not worth your time. Thanks for the reference link, I looked over it and don't think that'll work for me, or at least wasn't sophisticated enough to know how it could :-) Commented Sep 1, 2022 at 2:24

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.