我正在创建一个脚本,我想在其中检查每个Web链接是否可以访问并且没有遇到错误。否则,如果遇到错误,则会截取该页面的屏幕截图。
我尝试添加errorignore,但仍然不能忽略该错误
{
"Name": "Project_1",
"CreationDate": "2019-5-7",
"Commands": [
{
"Command": "store",
"Target": "2",
"Value": "!csvReadLineNumber"
},
{
"Command": "store",
"Target": "true",
"Value": "!errorignore"
},
{
"Command": "store",
"Target": "0",
"Value": "n"
},
{
"Command": "store",
"Target": "0",
"Value": "number"
},
{
"Command": "csvRead",
"Target": "urls.csv",
"Value": ""
},
{
"Command": "while",
"Target": "${!csvReadLineNumber}!=${!csvreadmaxrow}",
"Value": "!csvReadLineNumber"
},
{
"Command": "storeEval",
"Target": "${number}+1",
"Value": "number"
},
{
"Command": "csvRead",
"Target": "urls.csv",
"Value": ""
},
{
"Command": "storeEval",
"Target": "${!csvReadLineNumber}+1",
"Value": "!csvReadLineNumber"
},
{
"Command": "storeEval",
"Target": "true",
"Value": "!waitforvisible"
},
{
"Command": "open",
"Target": "${!COL3}",
"Value": ""
},
{
"Command": "echo",
"Target": "${number} ${!COL3}",
"Value": ""
},
{
"Command": "storeTitle",
"Target": "",
"Value": "title"
},
{
"Command": "verifyTitle",
"Target": "${title}",
"Value": ""
},
{
"Command": "echo",
"Target": "${title}",
"Value": ""
},
{
"Command": "storeEval",
"Target": "title =\"${title}\".match(404)",
"Value": "match"
},
{
"Command": "if",
"Target": "${MATCH}!=null",
"Value": ""
},
{
"Command": "storeEval",
"Target": "${n}+1",
"Value": "n"
},
{
"Command": "echo",
"Target": "Error 404 Found ${!COL3}",
"Value": ""
},
{
"Command": "captureEntirePageScreenshot",
"Target": "error ${n}",
"Value": ""
},
{
"Command": "endif",
"Target": "",
"Value": ""
},
{
"Command": "endWhile",
"Target": "",
"Value": ""
}
]
}
即使有错误,循环也应继续。但是实际结果是,当网页为“ 404”或“找不到页面”时,脚本会停止并提示错误
[error][ignored]Error in runEval code: call to eval() blocked by CSP
[error][ignored]Error in runEval condition of if: call to eval() blocked by CSP
[error][ignored]Error in runEval condition of while: call to eval() blocked by CSP
答案 0 :(得分:1)
该网站似乎阻止了脚本的执行。 storeEval中的Javascript是在网站的上下文中运行的。
解决方法:一种解决方法是在运行storeEval时切换到其他网站(例如,在其他标签中打开a9t9.com),然后再切换回去。
此解决方案来自Stringify runeval error和CSP error。