开发者

Unable to get CSS Selector "nth-type" working with WebDriver

开发者 https://www.devze.com 2023-02-27 07:07 出处:网络
Though have been able to use simple CSS (just including id, name) but \"nth-type\" gives up. Here is the test method -

Though have been able to use simple CSS (just including id, name) but "nth-type" gives up.

Here is the test method -

public static String GetTextByCSSSelector(IWebDriver webDriver, String cssLocator)
    {
        return we开发者_高级运维bDriver.FindElement(By.CssSelector(cssLocator)).Text;
    }

and this is the method call -

GetTextByCSSSelector(_webDriver, "css=div#filelist div:nth-child(1)");

and this is the exception -

OpenQA.Selenium.WebDriverException : An invalid or illegal string was specified

I used the locator mentioned above in Selenium IDE and it does highlight the element. Any guess?

#

On a different note, did you support Selenium Proposal on area51 - http://area51.stackexchange.com/proposals/4693/selenium You just need to click Commit button to support site, while having logged using your Google/Yahoo account. This proposal is backed by SeleniumHQ and we need more users to commit to it to make it see day of light.

#


Try div:first-child.

If that works it would imply that you only have CSS2 ability, not CSS3 ability.


Remove css= from selector, and enjoy :)

0

精彩评论

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