排除某個因素,第一優選想到正則表達式,無奈折騰半天沒有成功,感受是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」]