我正在使用Selenium 2.0,我想测试正在测试的正确的规范链接。我如何使用c#中的webdriver获取此内容?
类似于:WebDriver.FindElementByName("head").FindElement(By.Rel....
<head>
<link href="http://www.test.com/canonical" rel="canonical" />
<link href="/Content/Reset.css" rel="stylesheet" type="text/css" />
<link href="/Content/Site.css" rel="stylesheet" type="text/css" />
...
答案 0 :(得分:0)
我没有特别尝试过,但我可能会这样做:
// Assume driver is a correctly initialized IWebDriver instance,
// pointed at the page in question
IWebElement head = driver.FindElement(By.TagName, "head");
// Could also use By.XPath here with an appropriate XPath expression like
// FindElement(By.XPath, "./link[@rel='canonical']")
IWebElement link = head.FindElement(By.CssSelector, "link[@rel='canonical']");
我唯一要提醒的是,找到元素可能会有问题。