我有这个页面:http://services.ce3c.be/ciprg/?countrys=ANGUILLA
我正在尝试获取文本(国家/地区和 IP)并使用以下命令打印它:
var content = driver.FindElement(By.XPath(@"/html/body/pre/text()")).Text;
Console.WriteLine(content);
但似乎不起作用。我怎样才能做到这一点?
删除“/text()” 来自 XPATH。您无法指向 Selenium 中的文本节点。
这有效:
var content = driver.FindElement(By.XPath(@"/html/body/pre")).Text;
Console.WriteLine(content);
driver.FindElement(By.XPath("//*[@id=\"content\"]/ul/li[13]/a")).Click();
driver.FindElement(By.CssSelector("input[type='checkbox']")).Click();
driver.FindElement(By.XPath("//*[@id=\"checkbox-example\"]/button")).Click();
String msg = driver.FindElement(By.Id("message")).Text;
Console.WriteLine(msg);