【发布时间】:2020-06-09 03:35:05
【问题描述】:
我使用 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);
【问题讨论】:
标签: c# selenium selenium-webdriver xpath xpath-1.0