Javascript 在对象内与HTML交互

Javascript 在对象内与HTML交互,javascript,node.js,selenium-webdriver,Javascript,Node.js,Selenium Webdriver,我正在使用axios从getnada.com消息api返回此对象。下面的对象是axios返回的对象。在该对象中是一些html代码(我尽了最大努力清理html)。是否仍然可以使用id=“ActivateButton”在url上启动某种类型的单击事件?我将node.js与SeleniumWebDriver一起使用 { uid: 'vxqFqoQGw60LYgFc3kwtbYwVA8U8f2', ib: 'tsljt8kq@getnada.com', f: 'noreply_healthid@

我正在使用axios从getnada.com消息api返回此对象。下面的对象是axios返回的对象。在该对象中是一些html代码(我尽了最大努力清理html)。是否仍然可以使用id=“ActivateButton”在url上启动某种类型的单击事件?我将node.js与SeleniumWebDriver一起使用

{ uid: 'vxqFqoQGw60LYgFc3kwtbYwVA8U8f2',
  ib: 'tsljt8kq@getnada.com',
  f: 'noreply_healthid@optum.com',
  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:optumsupport@optum.com">optumsupport@optum.com</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: 'noreply_healthid@optum.com',
{uid:'vxqFqoQGw60LYgFc3kwtbYwVA8U8f2',
伊布:'tsljt8kq@getnada.com',
f:诺雷普利_healthid@optum.com',
s:'确认您的Optum ID电子邮件地址',
d:错,
地址:【】,
r:1532531106,
html:'\n\n
\n
\n
\n您的Optum ID帐户信息\n\n
\n
.textRegular\n
{\n
颜色:#000;\n
字体系列:“Arial常规”、“Arial”;\n
字体大小:13px;\n
}\n\n
.textRegularBold\n
{\n
字体系列:“Arial常规”、“Arial”;\n
字体大小:13px;\n
字体大小:粗体;\n
}\n\n
.textTitle\n
{\n
颜色:#C36121;\n
字体系列:“Arial粗体”、“Arial”;\n
字体大小:16px;\n
字体大小:粗体;\n
}\n\n
.tableCellBorder\n
{\n
边框:1px实心#ccc;\n
填充:15px;\n
边距:0px;\n
}\n\n
.tableWhole\n
{\n
边框:0px;\n
填充:0px;\n
边距:0px;\n
边框折叠:折叠;\n
}\n\n
\n
\n
\n
\n\n\n\n\n\n\n\n\n\n
\n
\n
\n
\n

只剩下一步,您的Optum ID就可以使用了。单击按钮:
\n\n\n\n\n\n\n\n\t\n\t \n\t\t\n\t\t\t\n\t\t\t\n\t\t\t \n\t\t \n\t \n\n\t

\n\t 如果愿意,请复制此10位代码2771832358,并将其粘贴到激活您的Optum ID页面上的激活代码框中。\n\t

\n\t

\n\t 如果您没有请求激活链接或代码,或者您对设置Optum ID有疑问,请致电1-855-819-5909或与我们联系。\n\t

\n\n\n \n \n

谢谢,\n

\n

眼睑ID

\n \n \n \n', 文本:“”, 事实上, 鲁:是的, 菲:诺雷普利_healthid@optum.com',
您可以使用操作DOM树

const cheerio=require('cheerio');
const json={html:'…'};
const$=cheerio.load(json.html);
常量脚本=`
ActivateClick(事件)上的函数{
//你在这里编码
}
`;
$('body').append(脚本);
$('#ActivateButton').attr('onclick','onActivateClick();');
const newHTML=$.html();

感谢您的建议!我能够刮取DOM并解析元数据以获得所需的链接。然后我使用执行脚本在新选项卡中打开链接

const json = { html: '...' };
const $ = cheerio.load(json.html);
var parsedResults = [];

$('a#ActivateButton').each(function(i, element){
    var url = $(this).attr('href');
    parsedResults.push(url);
});

browser.executeScript('window.open("' + parsedResults[0] + '");');