html复合html 颜色选择器器问题!

1817人阅读
基本CSS选择器有标记选择器、类别选择器、ID选择器3种
1。标记选择器
&&&& 每一种HTML标记的名称都可以作为相应的标记选择器的名称,如h1,p,等等
2。类别选择器
&&&& 类别选择器的名称可以由用户自定义
&& 格式如下:.class{color:font-size:20}
3。ID选择器
&&&& 与类别选择器相试
&& 格式如下:#id{color:font-size:20}
复合选择器:就是两个或者多个基本选择器,通过不同方式连接而成的选择器
有两种情况:”交集“选择器、“并集”选择器&
1。“交集”选择器:由两个选择器直接连接构成,其结果是选中二者各自元素范围的交集,其中第一必须是标记选择器,第二个必须是类别选择器或者ID选择器,两个选择器之间不能有空格,必须连续书写
如:h3.class{color:font-size:23}
2。“并集”选择器:同时选中各个基本选择器所选择的范围,任何形式的选择器都可以,并集选择器是多个选择器通过逗号连接而成的,
格式如:h1,h2,h3{color:font-size:23}
后代选择器:
后代选择器书写方法:把外层的标记写在前面,内层的标记写在后面,之间用空格分隔,当标记发生嵌套时,内层的标记就成为外层标记的后代了
&title&后代选择器&/title&
&style&type=&text/css&&
color:blue;
&p&嵌套&span&用CSS&/span&标记的方法&/p&嵌套之外的&span&标记&/span&不生效
效果是:“用CSS”的显示红色,其他用&span&包围起来的是兰色
后代选择器产生的影响不仅限于元素的“直接后代”,而且会影响到它的“各级后代”
子选择器:也就是只有对直接后代有影响的选择器,而对“孙子”以及对个层的后代不产生作用。
格式如下:p&span{color:}
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:34306次
排名:千里之外
转载:39篇
(1)(2)(5)(1)(11)(1)(11)(16)Compound class names are not supported error in WebDriver [复合类名不支持WebDriver误差] - 问题-字节技术
Compound class names are not supported error in WebDriver
复合类名不支持WebDriver误差
问题 (Question)
I have a method to count the number of elements in divs and to return their number.
public int getNumberOfOpenBets() {
openBetsSlip = driver.findElement(By.id("form_open_bets"));
openBets = openBetsSlip.findElements(By.className(" cashout_noCash"));
return openBets.size();
That's the page source
&form id="form_open_bets" method="post" name="form_open_bets"&
&input type="hidden" value="" name="action"&
&input type="hidden" value="" name="bet_id"&
&input type="hidden" value="" name="cashout_price"&
&input id="target_page" type="hidden" value="" name="target_page"&
&div id="By.id" class="slipWrapper "&
&div id="openBets_header"&&/div&
&div id="cashout_1626" class=" cashout_noCash"&
&div id="cashout_1625" class=" cashout_noCash"&
&div id="cashout_1615" class=" cashout_noCash"&
&div id="cashout_1614" class=" cashout_noCash"&
&div id="cashout_1613" class=" cashout_noCash"&
WebDriver is throwing the following error: Compound class names are not supported. Consider searching for one class name and filtering the results or use CSS selectors.
org.openqa.selenium.InvalidSelectorException: Compound class names are not supported. Consider searching for one class name and filtering the results or use CSS selectors.
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: ' 13:51:26'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_17'
Driver info: driver.version: unknown
at org.openqa.selenium.By.className(By.java:131)
at elements.betslip.Betslip.getNumberOfOpenBets(Betslip.java:136)
at testSomething(SomethingTest.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
As it turned out WerbDriver doesn't support spaces in the class names, omg. Could you guys please help me to use CSS selector in this situaltion in order to find the elements?
我有一个方法来计算在div元素的数量和返回他们的号码。public int getNumberOfOpenBets() {
openBetsSlip = driver.findElement(By.id("form_open_bets"));
openBets = openBetsSlip.findElements(By.className(" cashout_noCash"));
return openBets.size();
页面的来源&form id="form_open_bets" method="post" name="form_open_bets"&
&input type="hidden" value="" name="action"&
&input type="hidden" value="" name="bet_id"&
&input type="hidden" value="" name="cashout_price"&
&input id="target_page" type="hidden" value="" name="target_page"&
&div id="By.id" class="slipWrapper "&
&div id="openBets_header"&&/div&
&div id="cashout_1626" class=" cashout_noCash"&
&div id="cashout_1625" class=" cashout_noCash"&
&div id="cashout_1615" class=" cashout_noCash"&
&div id="cashout_1614" class=" cashout_noCash"&
&div id="cashout_1613" class=" cashout_noCash"&
WebDriver扔以下错误:不支持复合类名。考虑寻找一个类名或使用CSS选择器和过滤结果。org.openqa.selenium.InvalidSelectorException: Compound class names are not supported. Consider searching for one class name and filtering the results or use CSS selectors.
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.31.0', revision: '1bd294d185a80fa4206dfeab80ba773c04ac33c0', time: ' 13:51:26'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_17'
Driver info: driver.version: unknown
at org.openqa.selenium.By.className(By.java:131)
at elements.betslip.Betslip.getNumberOfOpenBets(Betslip.java:136)
at testSomething(SomethingTest.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
编辑:结果WerbDriver类名不支持空格,omg。请你们帮我使用CSS选择器在这个situaltion为了找到的元素呢?
最佳答案 (Best Answer)
This is exactly as expected. If your class name includes a space, WebDriver will see it as a "compound selector". You can either remove the space in your By.className() locator, which should still find the elements you' or you can move to finding by CSS selectors, using something like By.cssSelector(".cashout_noCash"), which offer far more flexibility for similar functionality. This is exactly what the exception message says.
这是与预期完全一致。如果你的类名包括空间,WebDriver将认为这是一个“复合选择器”。您可以删除在你的空间By.className()定位器,还是应该找到你要找的元素,或者你可以找到由CSS选择器,使用类似By.cssSelector(".cashout_noCash")类似的功能,提供更大的灵活性。这正是异常消息说。
答案 (Answer) 2
driver.findElements(By.cssSelector(".cashout_noCash"));
driver.findElements(By.cssSelector(".cashout_noCash"));
答案 (Answer) 3
You can include compound class names selectors by leaving no gap between any of them.
For example if your div is:
&div class="k-calendar-container k-popup k-group k-reset"&&/div&
then your selector will be:
driver.findElement(By.cssSelector("k-calendar-container.k-popup.k-group.k-reset"));
您可以包括复合类名称选择器的离开没有任何差距。例如如果你的div:&div class="k-calendar-container k-popup k-group k-reset"&&/div&那么你的选择将会是:driver.findElement(By.cssSelector("k-calendar-container.k-popup.k-group.k-reset"));
本文翻译自StackoverFlow,英语好的童鞋可直接参考原文:ckook|LOFTER(乐乎) - 记录生活,发现同好
LOFTER for ipad —— 记录生活,发现同好
&nbsp&nbsp被喜欢
&nbsp&nbsp被喜欢
{list posts as post}
{if post.type==1 || post.type == 5}
{if !!post.title}${post.title|escape}{/if}
{if !!post.digest}${post.digest}{/if}
{if post.type==2}
{if post.type == 3}
{if !!post.image}
{if post.type == 4}
{if !!post.image}
{if !!photo.labels && photo.labels.length>0}
{var wrapwidth = photo.ow < 500?photo.ow:500}
{list photo.labels as labs}
{var lbtxtwidth = Math.floor(wrapwidth*(labs.ort==1?labs.x:(100-labs.x))/100)-62}
{if lbtxtwidth>12}
{if !!labs.icon}
{list photos as photo}
{if photo_index==0}{break}{/if}
品牌${make||'-'}
型号${model||'-'}
焦距${focalLength||'-'}
光圈${apertureValue||'-'}
快门速度${exposureTime||'-'}
ISO${isoSpeedRatings||'-'}
曝光补偿${exposureBiasValue||'-'}
镜头${lens||'-'}
{if data.msgRank == 1}{/if}
{if data.askSetting == 1}{/if}
{if defined('posts')&&posts.length>0}
{list posts as post}
{if post_index < 3}
{if post.type == 1 || post.type == 5}
{if !!post.title}${post.title|escape}{/if}
{if !!post.digest}${post.digest}{/if}
{if post.type == 2}
{if post.type == 3}
{if post.type == 4}
{if drlist.length>0}
更多相似达人:
{list drlist as dr}{if drlist.length === 3 && dr_index === 0}、{/if}{if drlist.length === 3 && dr_index === 1}、{/if}{if drlist.length === 2 && dr_index === 0}、{/if}{/list}
暂无相似达人,
{if defined('posts')&&posts.length>0}
{list posts as post}
{if post.type == 2}
{if post.type == 3}
{if post.type == 4}
this.p={ currentPage:1,pageNewMode:true,isgooglead3:false,ishotrecompost:false,visitorId:0, first:'',tag:'ckook',recommType:'new',recommenderRole:0,offset:13,type:0,isUserEditor:0,};CSS所有的选择器类型总结_图文_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
CSS所有的选择器类型总结
上传于||文档简介
&&C&#8203;S&#8203;S&#8203;所&#8203;有&#8203;的&#8203;选&#8203;择&#8203;器&#8203;类&#8203;型&#8203;总&#8203;结
大小:1.40MB
登录百度文库,专享文档复制特权,财富值每天免费拿!
你可能喜欢

我要回帖

更多关于 html5 选择器 的文章

 

随机推荐