Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.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# SeleniumWebDriver和C(VS):查找特定的头字符串_C#_Selenium_Selenium Webdriver - Fatal编程技术网

C# SeleniumWebDriver和C(VS):查找特定的头字符串

C# SeleniumWebDriver和C(VS):查找特定的头字符串,c#,selenium,selenium-webdriver,C#,Selenium,Selenium Webdriver,我一直在尝试使用IJavaScriptExecutor在页面中查找特定的标题字符串,但运气不好。以下是该页面的html代码: <div class="wrap"> <h2>Edit Page <a href="http://www.webtest.bugrit.net/wordpress/wp-admin/post- new.php?post_type=page" class="add-new-h2">Add New</a></h

我一直在尝试使用IJavaScriptExecutor在页面中查找特定的标题字符串,但运气不好。以下是该页面的html代码:

<div class="wrap">
   <h2>Edit Page <a href="http://www.webtest.bugrit.net/wordpress/wp-admin/post-
   new.php?post_type=page" class="add-new-h2">Add New</a></h2>
<div id...
现在,我意识到我期望从代码中获得的文本不是确切的字符串编辑页面。但它不应该返回一些东西吗?启用MessageBox行时,innerHtml字符串为空

或者,当然-如果有人知道另一种可能更简单的方法来检查特定html标记中是否存在特定字符串,我洗耳恭听。

您的元素返回您的元素,而不是。您的页面不包含编辑页面字符串

仅当类名add-new-h2唯一时,才尝试在父元素中查找这样的元素,否则将得到第一个匹配的元素:

var element = FFDriver.Instance.FindElement(By.XPath(".//a[@class='add-new-h2']/.."));
var containsText = element.Text.Contains("Edit Page");

那么element.Text返回什么呢?你是说innerHtml.Text吗?那种方法行不通。但是,innterHtml.toString在对象未设置为引用时崩溃。。。错误。'System.Collections.ObjectModel.ReadOnlyCollection'不包含'Text'的定义,并且找不到接受'System.Collections.ObjectModel.ReadOnlyCollection'类型的第一个参数的扩展方法'Text'。是否缺少using指令或程序集引用?是否。首先在最后:FFDriver.Instance.FindElementsBy.XPath//首先是[@class='add-new-h2']/;
var element = FFDriver.Instance.FindElement(By.XPath(".//a[@class='add-new-h2']/.."));
var containsText = element.Text.Contains("Edit Page");