Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';找不到document.querySelector的atag链接_Javascript_Html_Queryselector_Atag - Fatal编程技术网

Javascript Can';找不到document.querySelector的atag链接

Javascript Can';找不到document.querySelector的atag链接,javascript,html,queryselector,atag,Javascript,Html,Queryselector,Atag,我试图找到一个包含以下内容的链接:ng click=“showModal()”,其内部文本为:1122334455 我尝试使用下面的代码,但找不到链接(atag)。我不确定使用的代码行中会出现什么问题:document.querySelector?(那条线就是问题所在) atag所在位置的HTML代码,如下所示: <td class="col-reservation-id text-center"> <span class="overflow-text"> &

我试图找到一个包含以下内容的链接:
ng click=“showModal()”
,其内部文本为:1122334455

我尝试使用下面的代码,但找不到链接(
atag
)。我不确定使用的代码行中会出现什么问题:
document.querySelector
?(那条线就是问题所在)

atag所在位置的HTML代码,如下所示:

<td class="col-reservation-id text-center">
  <span class="overflow-text">
    <a class="highlight" ng-click="showModal()">1122334455</a>
  </span>
</td>

1122334455
C#/javascript代码以查找上述atag

public async Task<bool> clicklink(ChromiumWebBrowser browser)
{
    String atag = "document.querySelector('" + "a[ng-click=" + '"' + "showModal()" + '"' + "].innerText === '1122334455'" + "')";

    String clickinputscript = atag + ".focus(); " +
                              atag + ".click(); ";

    bool success = false;
    try
    {
        success = (await browser.GetMainFrame().EvaluateScriptAsync(clickinputscript)).Success;
    }
    catch (Exception ex) { success = false; }
    return success;
}
公共异步任务点击链接(ChromiumWebBrowser)
{
字符串atag=“document.querySelector”(“+”a[ng click=“+””“+”showmodel()“+”“+”)。innerText==“1122334455+”)”;
字符串clickinputscript=atag+“.focus();”+
atag+”。单击();”;
布尔成功=假;
尝试
{
成功=(等待browser.GetMainFrame().EvaluateScript异步(clickinputscript))。成功;
}
catch(异常ex){success=false;}
回归成功;
}

可能是因为ng click不适合html属性,请尝试按id或类查找:)

您不能将JS代码放在
文档中。querySelector
的查询字符串中

你必须在选择后再做。要执行此操作,请使用
document.querySelectorAll
for
循环:

for(const element of document.querySelectorAll('a[ng-click="showModal()"]').values()){
  if(element.innerText === '1122334455'){
    element.focus()
    element.click()
    break
  }
};
或者,转换为C#land:


@charlietfl我认为我正确地使用了引号?我知道可以使用ng click属性来查找标记,但我的代码中还有其他错误:)这很好。我现在明白你的意思了。这确实很好!。非常感谢您对FZs的帮助!
String clickinputscript = "for(const element of document.querySelectorAll('a[ng-click=" + '"showModal()"'+"]').values()){if(element.innerText === '1122334455'){element.focus();element.click();break;};};";