原文地址: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
 

Compound class names are not supported. Consider searching for one class name and filtering the results的更多相关文章

  1. 【Selenium专题】 FAQ_对象识别_Compound class names are not supported

    测试代码 public void login(){ WebDriver driver = new ChromeDriver(); driver.get("http://IP:Port/cli ...

  2. selenium的报错信息:selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Compound class names not permitted

    报错信息:selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Compound class ...

  3. InvalidSelectorError: Compound class names not permitted报错处理

    InvalidSelectorError: Compound class names not permitted报错处理 环境:python3.6 + selenium 3.11 +  chromed ...

  4. selenium实战-Compound class names not permitted

    这个复合类其实就是嵌套类,使用最后一个作为类名即可

  5. java-selenium(一)元素定位

    在定位单个元素时,selenium-webdriver 提示了如下一些方法对元素进行定位.下面这些定位方式中,优先使用 id.name.classname,对于网上的链接元素,推荐使用linkText ...

  6. 译:Spring框架参考文档之IoC容器(未完成)

    6. IoC容器 6.1 Spring IoC容器和bean介绍 这一章节介绍了Spring框架的控制反转(IoC)实现的原理.IoC也被称作依赖注入(DI).It is a process wher ...

  7. Spring4参考手册中文版

    Spring4参考手册中文版 前言 https://github.com/b2gats/stone-docs/blob/master/spring-4-beans.md Part III. 核心技术 ...

  8. python查找时,不支持compound class

    1.python使用如下代码查找页面上的元素时, browser.findElement_by_class_name("widget-content nopadding") 报错: ...

  9. Sphinx 2.2.11-release reference manual

    1. Introduction 1.1. About 1.2. Sphinx features 1.3. Where to get Sphinx 1.4. License 1.5. Credits 1 ...

随机推荐

  1. 3D打印论坛

    3D打印论坛:http://www.3done.cn http://www.03dp.com www.qjxxw.net/ http://www.3ddayin.net http://oa.zol.c ...

  2. hdu2768-Cat vs. Dog:图论:二分匹配

    Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. SpringMVC接收复杂集合参数

    Spring MVC在接收集合请求参数时,需要在Controller方法的集合参数里前添加@RequestBody,而@RequestBody默认接收的enctype (MIME编码)是applica ...

  4. zoj 3811 Untrusted Patrol(bfs或dfs)

    Untrusted Patrol Time Limit: 3 Seconds      Memory Limit: 65536 KB Edward is a rich man. He owns a l ...

  5. (转)iOS7界面设计规范(3) - UI基础 - 启动与退出

    周二晚间来第三发,搞得好像今天是周六的赶脚.发掉之后再奖励自己一点冰啤酒吧,然后扑床去.天气热起来了,各位注意防暑降温呗.走起. 重要:这是针对于正在开发中的API或技术的预备文档(预发布版本).虽然 ...

  6. hdu 2853

    虚拟赛一开始lyf就对我说这是一道匹配的题目,我一看明显裸的最优匹配,敲完提交wrong, 题目要求改变尽量少的公司,就是如果遇到相等的权值,优先选择跟他原来匹配的,KM匹配是按序号大小来的,如果一个 ...

  7. 解决linux不能使用chmod更改权限的问题

    本人安装的是win10和ubuntu的双系统,发现在ubuntu下挂载windows硬盘不用命令chmod更改文件的权限,解决方法记录如下: 对于使用命令$ chmod 777 dirname更改不了 ...

  8. Verilog 读写文件

    Verilog 读写文件 在数字设计验证中,有时我们需要大量的数据,这时可以通过文件输入,有时我们需要保存数据,可以通过写文件保存. 读写文件testbench module file_rw_tb() ...

  9. ASP.net获取当前页面的文件名,参数,域名等方法

    ASP.net后台获取当前页面的文件名 System.IO.Path.GetFileName(Request.Path).ToString(); 获取当前页面文件名,参数,域名等方法 假设当前页完整地 ...

  10. Javascript实现表格行排序

    网站开发中凡是用到表格来展示数据的,往往都要根据某个列来对行排序,下面是我从书上看到的一个行排序例子,看过后受益匪浅,故分享出来. 直接献上完整代码: <!doctype html> &l ...