Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interacting with HTML inside an object

I'm using axios to return this object from getnada.com messages api. The object below is what axios returns. Inside that object is some html code (did my best to clean up the html). Is there anyway to initiate some sort of click event on the url with id="ActivateButton"? I'm using node.js with selenium-webdriver.

{ uid: 'vxqFqoQGw60LYgFc3kwtbYwVA8U8f2',
  ib: '[email protected]',
  f: '[email protected]',
  s: 'Confirm your Optum ID email address',
  d: false,
  at: [],
  r: 1532531106,
  html: '<!DOCTYPE HTML>\n<html lang="en">\n
                <head>\n    
                    <meta charset="utf-8"/>\n    
                    <title>\n        Your Optum ID account information\n    </title>\n    
                    <style type="text/css">\n
                        .textRegular\n
                        {\n            
                            color:#000;\n            
                            font-family:"Arial Regular","Arial";\n            
                            font-size:13px;\n        
                        }\n\n        
                            .textRegularBold\n        
                        {\n            
                            font-family:"Arial Regular","Arial";\n            
                            font-size:13px;\n            
                            font-weight:bold;\n        
                        }\n\n        
                            .textTitle\n        
                        {\n
                            color:#C36121;\n            
                            font-family:"Arial Bold","Arial";\n            
                            font-size:16px;\n            
                            font-weight:bold;\n        
                        }\n\n        
                            .tableCellBorder\n        
                        {\n            
                            border: 1px solid #ccc;\n            
                            padding: 15px;\n            
                            margin: 0px;\n        
                        }\n\n        
                            .tableWhole\n        
                        {\n            
                            border: 0px;\n
                            padding: 0px;\n            
                            margin: 0px;\n            
                            border-collapse:collapse;\n        
                        }\n\n    
                    </style>\n
                </head>\n
                <body>\n
                    <div class="content" role="main">\n\n\n\n\n\n\n\n\n
                        <table style="border: 0px; padding: 0px; margin: 0px; border-collapse:collapse; font-family: \'Arial Regular\', \'Arial\'; font-size: 13px;" role="presentation">\n    
                            <tr>\n        
                                <td style="border: 1px solid #ccc; padding: 15px; margin: 0px;">\n        
                                    <img  alt="MAHealthConnector" src="https://stg2-healthid.optum.com/tb/services/rest/rp/rpapplogo?rpid=MHC28623">\n        
                                    <h1 style="font-size: 16px; color: #924719; font-weight: bold; font-family: \'Arial Bold\' , \'Arial\';margin-top: 0px !important; margin-bottom: 7px !important;" id="emailHeading"><br/>
                                        Just one step left to do and your Optum ID will be ready to use. Click the button:<br/>
                                    </h1>\n\n\n\n\n\n\n\t\n\t
                                    <table cellspacing="0" cellpadding="0">\n\t\t<tr>\n\t\t\t<td align="center" style="color: #000; font-family: \'Arial Regular\', \'Arial\'; font-size: 13px;;  display: block; background-color:#f3f3f3;">\n\t\t\t<a style="display: inline-block; font-size: 17px; background-color:#f3f3f3; width: 200px; height: 28px; padding: 26px; text-decoration: none; color: #333333; border: 1px solid #333333; text-align: center;" href="https://stg2-healthid.optum.com/tb/link/verify-account?verificationDetails=5OFHzqRihZbR0c5g4aZW9s1HBwjg9eJ%2Fdm%2BVF%2FdeuZzV1Eofn8UJZFY37qCXmN6RRB3rHEwCk1iFwXcyVpm5VFbOAYyIV7c1nSYZ3nhTBS6cji3DyItOHmS3OjQHSzJjJibmormBRYYDues%2BI6l08fFBu42eYeoAyj16y1rb3984nAqSPPP6Yko5MBipXNI8bUR3VeObg57TdzNSDfqIGNq%2FxQk6h0UwP4QQVodihvVg3ew8f4j44IAFaipXXONoYxqLZuWSbe3d39WFKe6pOg2R9XBzXeSKk0TjtbxPOjI%3D&relyingAppId=MHC28623" id="ActivateButton">Activate my Optum ID\n</a>\n\t\t\t
                                </td>\n\t\t
                            </tr>\n\t
                        </table>\n\n\t
                        <p style="color: #000; font-family: \'Arial Regular\', \'Arial\'; font-size: 13px;margin-top: 0px !important; margin-bottom: 7px !important;; margin-top: 20px !important;" id="emailRegistrationPrimaryCode">\n\t
                            If you prefer, copy this 10-digit code 2771832358 and paste it into the boxfor the activation code on the Activate Your Optum ID page.\n\t
                        </p>\n\t
                        <p style="color: #000; font-family: \'Arial Regular\', \'Arial\'; font-size: 13px;margin-bottom: 0;display: inline;" id="emailRegistrationPrimaryNotRequestedMsg">\n\t
                            If you did not request an activation link or code, or if you have questions about setting up an Optum ID, contact us at 1-855-819-5909 or <a href="mailto:[email protected]">[email protected]</a>.\n\t
                        </p>\n\n\n
                    </div>\n
                    <div role="contentinfo">\n
                        <p style="margin: 26px 0 0;" id="emailThank">
                            Thank you,\n
                        </p>\n
                        <p style="margin:0;" id="companyName">
                            Optum ID
                        </p>\n
                    </div>\n
                </body>\n
            </html>\n',
  text: '',
  in: true,
  ru: true,
  fe: '[email protected]',

1 Answers

You can manipulate the DOM tree with cheerio.

const cheerio = require('cheerio');

const json = { html: '...' };
const $ = cheerio.load(json.html);
const script = `
    <script>
        function onActivateClick(event){
            // YOU CODE HERE
        }
    </script>
`;
$('body').append(script);
$('#ActivateButton').attr('onclick', 'onActivateClick();');

const newHTML = $.html();
like image 119
Ramy Ben Aroya Avatar answered Mar 13 '26 20:03

Ramy Ben Aroya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!