1. By.cssSelector-java:
1.1 Class : driver.findElement(By.cssSelector("span.input-group-btn > button.btn.btn-default")).click();
1.2 id - java
Java 代码
1.<input id="passport_51_user" type="text" value="" tabindex="1" title="用户名/彩虹号/邮箱" name="passport_51_user">
使用css 定位,Java 代码
1. WebElement e1 = dr.findElement(By.cssSelector("#passport_51_user"));
*******************************************************************************
Class-python
1.driver.find_element_by_css_selector("span.glyphicon.glyphicon-plus").click()
<a href="javascript:;" title="添加主题" οnclick="taskGroupInput(null,'1');" style="color:#5b5b5b">
<span class="glyphicon glyphicon-plus"></span>
</a>
ID-Python
2. #analysis > div > p
<li id="analysis" href="http://xxxxxxxxxx/yyy.action" class="tile tile-big tile-9" data-page-type="r-page" data-page-name="random-r-page">
<div>
<p><img src="http://xxxxxxxxxx/yyy.png" style="width:55px;height:55px;">
PPPP
</p>
<span class="intro" style="margin-left: -77%;"><small>Event Analysis</small></span>
</div>
</li>
#sameContent_tmp_-2175149931484563833 > td:nth-child(1) > input[type="checkbox"]
<tr id="sameContent_tmp_-2175149931484563833">
<td width="10px;">
<input type="checkbox" name="cbx" value="-2175149931484563833" οnclick="setChkAllStatus(this.checked,'-2175149931484563833')">
</td>
<td>......</td>
</tr>
例:3 #assetIn_div > div:nth-child(3) >a.left_option.left_option_half.left_option_active
<div>...</div>
<div>...</div>
<div>
<a class="left_option left_option_half" ... </a>
< a class="left_optionleft_option_half left_option_active" ... </a>
</div>
</div>
定义和用法 ::nth-child(n) 选择器匹配属于其父元素的第 N 个子元素,不论元素的类型。 n 可以是数字、关键词或公式。
<html>
<head>
<style>
p:nth-child(2) //如果此处改成child(1),下面没有元素被标红; // 如果此处改成child(2),去掉下面的<h1>元素,<p>第二个段落被标红
{
background:#ff0000;
}
</style>
</head>
<body>
<h1>这是标题</h1>
<p>第一个段落。</p> <!--此处背标红色 -->
<p>第二个段落。</p>
<p>第三个段落。</p>
<p>第四个段落。</p>
<p><b>注释:</b>Internet Explorer 不支持 :nth-child() 选择器。</p>
</body>
</html>
=======XPath=======
driver.findElement(By.xpath("//div[@id='taskGroup_div']/div/a/span[2]/b")).click();
========================
http://101lichunmei.blog.163.com/blog/static/2858314720136234313971/