2011-07-22 69 views
0

我使用Selenium 2.0,我想測試正在測試的正確的規範鏈接。我怎麼會得到這個在c#中使用webdriver?C#Selenium 2測試Canonical Linke

喜歡的東西: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

我還沒有試過這種特別的,但我可能會接近它是這樣的:

// 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']"); 

我想提醒的唯一的事情是,發現元素可能會有問題。