开发者

C# Selenium 2 Test Canonical Linke

I'm using Selenium 2.0 and I want to test the correct cano开发者_开发百科nical link is being tested. How would I get this using the webdriver in c#?

Something like: 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" />
   ...


I haven't tried this specifically, but I'd probably approach it like this:

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

The only thing I'd caution about is that finding elements under may be problematic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜