排除某个因素,第一优选想到正则表达式,无奈折腾半天没有成功,感受是selenium对元素的attrs按re search在操做,$对字符串末尾检测都没什么用。python
BeautifulSoup能够用element[‘class’]输出元素的class进行检测,可是BeautifulSoup对象不能再进行click操做,不符合指望。selenium没有这样的语法,经过xpath进行选择:正则表达式
itemList = driver.find_elements_by_xpath('//div[@id = "choose-color"]//div[@class = "dd"]//div[not(contains(@class, "disabled"))]')
stackoverflow有个参考:http://stackoverflow.com/questions/11024080/how-to-use-not-contains-in-xpathexpress
补充xpath用法:spa
xpath=xpathExpression: Locate an element using an XPath expression. xpath=//img[@alt=’The image alt text’] xpath=//table[@id=’table1’]//tr[4]/td[2] xpath=//a[contains(@href,’#id1’)] xpath=//a[contains(@href,’#id1’)]/@class xpath=(//table[@class=’stylee’])//th[text()=’theHeaderText’]/../td xpath=//input[@name=’name2’ and @value=’yes’] xpath=//*[text()=”right”]