Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.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
C# Selenium:有没有办法在整个页面中搜索给定的关键字?_C#_Search_Selenium - Fatal编程技术网

C# Selenium:有没有办法在整个页面中搜索给定的关键字?

C# Selenium:有没有办法在整个页面中搜索给定的关键字?,c#,search,selenium,C#,Search,Selenium,我正在测试一个与谷歌非常相似的网站。因此,如果用户输入一些搜索词,比如“Selenium Tutorial”,结果页面就会有一堆带有代码片段的链接 每个结果都在一个表中。所以,如果有10个结果,就有10个表格。 对于每个表(结果),有几行(比如r1、r2、r3等)。r1是结果的标题,r2是大小、格式、作者等描述,r3是代码段。我需要确保r3包含单词“selenium”“tutorial”。我试过这样做: String variable2 = Sel.GetTable("//div[@id='Re

我正在测试一个与谷歌非常相似的网站。因此,如果用户输入一些搜索词,比如“Selenium Tutorial”,结果页面就会有一堆带有代码片段的链接

每个结果都在一个表中。所以,如果有10个结果,就有10个表格。 对于每个表(结果),有几行(比如r1、r2、r3等)。r1是结果的标题,r2是大小、格式、作者等描述,r3是代码段。我需要确保r3包含单词“selenium”“tutorial”。我试过这样做:

String variable2 = Sel.GetTable("//div[@id='RepeaterContent']/table[2].3.1");
这给了我r3中的文本,片段。但是,我需要获取所有表(结果)的文本(片段)。然后使用类似于contains的内容对代码段执行搜索

我不确定以下代码是否有用,因为我无法复制源代码,但结果页的源代码如下所示:

<HTML>
<BODY>
<DIV id="RepeaterContent">
<TABLE>
<TR>
  <TD>
    <SPAN>
      <a id="linkcft87021" class="ResultList_Title_Link" title="" href="DocsDetail.aspx?searchtranid=1bnt5d92" target="">Sample Tutorial</a>
      <br>
    </SPAN>
   </TD>
</TR>

<TR>
  <TD>
    ...an integrated development environment for performing Selenium tests...
  </TD>
</TR>
</TABLE>

<TABLE>
<TR>
  <TD>
    <SPAN>
      <a id="linkcft87021" class="ResultList_Title_Link" title="" href="DocsDetail.aspx?searchtranid=1g5t5d92" target="">Selenium</a>
      <br>
    </SPAN>
   </TD>
</TR>

<TR>
  <TD>
    ...With Selenium you can automate the whole process and run the test as required. In this part we will see how to create a simple test in Selenium... 
  </TD>
</TR>
</TABLE> 

</BODY>
</HTML>

所以,我想确保在整个结果页面中有“Selenium”和“Tutorial”两个词。硒有没有一种方法可以满足我的要求?在整个页面中搜索这些关键字并验证关键字是否存在的一些方法?提前感谢。

Selenium有一个getBodyText方法,可以为您提供整个页面的HTML文本。

Selenium有一个getBodyText方法,可以为您提供整个页面的HTML文本。

您可以使用
IsTextPresent(pattern)
检查页面上是否有特定的字符串
pattern
可以是
glob
regexp
exact
中的一种,默认值为
glob
,您可以使用
IsTextPresent(pattern)
检查页面上是否有特定的字符串<代码>模式可以是
glob
regexp
exact
,默认为
glob

    try {
    $this->assertTrue((bool)preg_match('/Selenium/',$this->getText("//div[@id='RepeaterContent']/table[1]/tbody/tr[2]/td")););
} catch (PHPUnit_Framework_AssertionFailedError $e) {
    array_push($this->verificationErrors, $e->toString());
}
这是PHP中所需的代码

您必须使用
命令验证文本 目标//tr[2]/td
regexp:Selenium

这将在给定目标中搜索Selenium,您可以替换所需的单词或使用RE

谢谢

这是PHP中所需的代码

您必须使用
命令验证文本 目标//tr[2]/td
regexp:Selenium

这将在给定目标中搜索Selenium,您可以替换所需的单词或使用RE


谢谢

有没有一种方法可以用来搜索getBodyText返回的HTML文本中的关键字?当我使用getBodyText时,它给我空值。有没有一种方法可以用来搜索getBodyText返回的HTML文本中的关键字?当我使用getBodyText时,它给我空值。谢谢!我尝试使用IsTextPresent(“Selenium教程”);但每次都返回false。@Maya您确定屏幕上显示的是确切的文本“Selenium Tutorial”吗?@Tnem:我正在使用IsTextPresent(“Selenium Tutorial”)的页面是一个带有片段链接的结果页面。因此,文本“Selenium教程”散布在这个结果页面上。另外,如果只找到单词“Selenium”或只找到单词“Tutorial”,我希望IsTextPresent()返回true。@Maya然后使用两个语句
IsTextPresent(“Selenium”)| | IsTextPresent(“Tutorial”)
@Tnem:我已经发布了上面的代码。非常感谢你试图帮助我。谢谢他们!我尝试使用IsTextPresent(“Selenium教程”);但每次都返回false。@Maya您确定屏幕上显示的是确切的文本“Selenium Tutorial”吗?@Tnem:我正在使用IsTextPresent(“Selenium Tutorial”)的页面是一个带有片段链接的结果页面。因此,文本“Selenium教程”散布在这个结果页面上。另外,如果只找到单词“Selenium”或只找到单词“Tutorial”,我希望IsTextPresent()返回true。@Maya然后使用两个语句
IsTextPresent(“Selenium”)| | IsTextPresent(“Tutorial”)
@Tnem:我已经发布了上面的代码。非常感谢你试图帮助我。
    try {
    $this->assertTrue((bool)preg_match('/Selenium/',$this->getText("//div[@id='RepeaterContent']/table[1]/tbody/tr[2]/td")););
} catch (PHPUnit_Framework_AssertionFailedError $e) {
    array_push($this->verificationErrors, $e->toString());
}