C# SyntaxError:未能执行';评估';在';文件';:字符串'//div[contains(,';Medium';)';不是使用Selenium的有效XPath表达式错误

C# SyntaxError:未能执行';评估';在';文件';:字符串'//div[contains(,';Medium';)';不是使用Selenium的有效XPath表达式错误,c#,selenium,selenium-webdriver,xpath,xpath-1.0,C#,Selenium,Selenium Webdriver,Xpath,Xpath 1.0,我使用selenium试图在html中获取div类值,但我遇到了如下问题 invalid selector: Unable to locate an element with the xpath expression //div[contains(., 'Medium') because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[contai

我使用selenium试图在html中获取div类值,但我遇到了如下问题

invalid selector: Unable to locate an element with the xpath expression //div[contains(., 'Medium') because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[contains(., 'Medium')' is not a valid XPath expression.
下面是我的html和读取html值的代码

HTML:

代码试用:

IWebElement element = driver.FindElement(By.XPath("//div[contains(., 'Medium')"));
String text =   element.GetAttribute("text");
Console.WriteLine(text);
此错误消息

invalid selector: Unable to locate an element with the xpath expression //div[contains(., 'Medium') because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[contains(., 'Medium')' is not a valid XPath expression.
…表示您使用的XPath不是有效的XPath表达式


你离得太近了。在构建过程中,你错过了结束
]

实际上,您的代码行是:

IWebElement element = driver.FindElement(By.XPath("//div[contains(., 'Medium')]"));

工具书类 您可以在以下内容中找到一些相关讨论:


您可以使用xpath表达式来关闭
]

IWebElement element = driver.FindElement(By.XPath("//div[contains(., 'Medium')]"));
String text = element.Text;
Console.WriteLine(text);

使用
element.text提取文本
元素.GetAttribute(“innerHTML”)

正在运行,谢谢!!!但我仍然无法在控制台中获取文本值。@JonathanK try
element.GetAttribute(“innerHTML”)
元素.Text实际上我想得到“媒体不像互联网上的其他平台”的值谢谢你的帮助谢谢..你知道如何设置元素的值吗?我想将“媒体不同于互联网上的其他平台”的值更改为其他措辞。@JonathanK否,它位于
标记内,如果手动无法更改文本,请使用selenium。@JonathanK很高兴能够帮助您。如果这个/任何答案对你有帮助,对未来的读者有好处。