zoukankan      html  css  js  c++  java
  • Compound class names are not supported. Consider searching for one class name and filtering the results

    原文地址:http://stackoverflow.com/questions/20361643/compound-class-names-are-not-supported-consider-searching-for-one-class-name-an

    使用webdriver定位元素方法By.ClassName("btn-buy jq-productdetail-buy")时报的错误,查找到上述资料,说是因为中间的空格,它会识别为两个元素,而如果这样定位By.ClassName("btn-buy"),则会定位到classname包含btn-buy的所有元素的第一个,所以解决方案如下:

    CssSelector (the best):

    driver.FindElement(By.CssSelector(".bighead.crb")); // flexible, match "bighead small crb", "bighead crb", "crb bighead", etc.
    driver.FindElement(By.CssSelector("[class*='bighead crb']")); // order matters, match class contains  "bighead crb"
    driver.FindElement(By.CssSelector("[class='bighead crb']")); // match "bighead crb" strictly

    XPath (the better):

    driver.FindElement(By.XPath(".//*[contains(@class, 'bighead') and contains(@class, 'crb')]")); // flexible, match "bighead small crb", "bighead crb", "crb bighead", etc.
    driver.FindElement(By.XPath(".//*[contains(@class, 'bighead crb')]")); // order matters, match class contains string "bighead crb" only
    driver.FindElement(By.XPath(".//*[@class='bighead crb']")); // match class with string "bighead crb" strictly
     
  • 相关阅读:
    CCF201612-2 工资计算(100分)
    CCF201612-2 工资计算(100分)
    CCF201609-2 火车购票(100分)
    CCF201609-2 火车购票(100分)
    CCF201604-2 俄罗斯方块(100分)
    CCF201604-2 俄罗斯方块(100分)
    CCF201312-2 ISBN号码(100分)
    CCF201312-2 ISBN号码(100分)
    JSP---Sql Jdbc和MySql Jdbc
    JS---正则表达式验证
  • 原文地址:https://www.cnblogs.com/techfans/p/4449636.html
Copyright © 2011-2022 走看看